Win a copy of Penetration Testing Basics this week in the Security forum!

# IS this question good? why

huanyu zhao
Greenhorn
Posts: 29
what is the value of j at line 17?
[ June 26, 2002: Message edited by: huanyu zhao ]

Chung Huang
Ranch Hand
Posts: 56
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.

geetha nagarajan
Ranch Hand
Posts: 94
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
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
& can take both boolean and integral operands.
&& can be applied to boolean expressions only.

Amir Ghahrai
Ranch Hand
Posts: 110
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?

geetha nagarajan
Ranch Hand
Posts: 94
To Amir,
Yes, && is short-circuited and not &.
Both operands r evaluated in case of &.

Francisco A Guimaraes
Ranch Hand
Posts: 182
good question huanyu, just one detail:

we always have to be aware of these little errors.
Francisco

huanyu zhao
Greenhorn
Posts: 29
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!

Deepali Pate
Ranch Hand
Posts: 114
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??