• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

IS this question good? why

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the value of j at line 17?
[ June 26, 2002: Message edited by: huanyu zhao ]
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by huanyu zhao:


Correct me if I am wrong, wouldn't this thing produce a compiler error at the line that says

since i>10 gives me boolean value which & don't take? Or is it a runtime error since express are evaluated during runtime...either way I thought & is a bitwise operator that only take integer, while boolean is never evaluated as integers.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The value of j would be 1 at line 17.
methodB() will be called only once,i.e in
b=i>10 & methodB(1);
Here, b=i>10 && methodB(2);

i>10 is false,so the methodB() will not be called.
[ June 26, 2002: Message edited by: geetha nagarajan ]
 
Chung Huang
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never mind, forgot about that short-circut nature
wouldn't j be 2? the call send over 2, and the line says j += k where j is 0 and k is the value send over which is 2.
[ June 26, 2002: Message edited by: Chung Huang ]
 
geetha nagarajan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
& can take both boolean and integral operands.
&& can be applied to boolean expressions only.
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To geetha
I thought the & operand is not short cutted!
only && is short-cutted. I thought the second operand always gets evaluated even if the first operand evaluates to false. but if you use && then if the result can be determined, then the second operand doesn't get evluated?
correct me please.
 
geetha nagarajan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To Amir,
Yes, && is short-circuited and not &.
Both operands r evaluated in case of &.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good question huanyu, just one detail:

we always have to be aware of these little errors.
Francisco
 
huanyu zhao
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by geetha nagarajan:
The value of j would be 1 at line 17.
methodB() will be called only once,i.e in
b=i>10 & methodB(1);
Here, b=i>10 && methodB(2);

i>10 is false,so the methodB() will not be called.
[ June 26, 2002: Message edited by: geetha nagarajan ]


oh good! thank you!
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code in your very first post does not the main() properly defined is that a typo???
Coz if it is not the prograom will fail to run right??
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic