A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
Joined: Sep 26, 2004
Oct 01, 2004 09:43:00
Which of the following will not compile without error?
Why the result is B not A ??
Joined: Sep 10, 2004
Oct 01, 2004 09:47:00
b1|b2 = bitwise manipulation
b1||b2 = boolean logic read b1 or b2.
Let's use a simple example for bitwise manipulation
int a = 1, b = 2, c;
c = a | b;
binary value a 0001 = 1
binary value b 0010 = 2
binary value c 0011 = 3
Rules for bit wise or are if on of the bits is 1, the result is 1.
Hope this helps.
SCJP 1.4 SCWCD 1.4
Joined: Aug 03, 2002
Oct 01, 2004 10:28:00
Both of these examples compile, and when run result in
The one involving the operator is the "non-shortcutting" logical OR operator when its operands are
. (It is also a bitwise or operator when its operands are integer types).
The second operator || is the "shortcutting" logical OR operator which takes only
Ask a Meaningful Question
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link:
subject: help required
Something about auto-boxing/unboxing in SE5
Associativity and precedence of Conditional operators
logical operator doubt
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015