|
|
|
|
|
|
|
|
|
|
if(department==1 || 2)
means if department == 1 IR if 2 == 2if(department == 1 || department == 2)
1. This doesn't do what you think if(department==1 || 2) means if department == 1 IR if 2 == 2 |
if( (department == 1) || 2)
if ( (3 == 1) || 2)
if ( false || 2 )
if (true)
if(department == 1 || 0)
if(department == 1 || 0)
- it's not always true. The correct explanation is mine above.ReedTompkins wrote: |
---|
if( (department == 1) || 2) due to order of operations. If we enter "3" we get: if ( (3 == 1) || 2) which translates to: if ( 0 || 2 ) which becomes: if (2) |
if( (department == 1) || 2)
department == 1
2
ResidentBiscuit (707) Mar 10, 2012 at 1:04am 1. This doesn't do what you think if(department==1 || 2) means if department == 1 IR if 2 == 2 You need something like if(department == 1 || department == 2) 2. In this situation, the parentheses are irrelevant. 3. = is an assignment operator, not a comparison. Essentially, this is assigning a as 0. This will always be true. == is the comparison, this is why you're not outputting the first option. Does it output 088? 4. Think about precedence. Does ++ precede +? 5. | is the Boolean or, and & is the Boolean and. http://www.cplusplus.com/doc/boolean/ 6 in binary is 110 and 5 in binary is 101. Should be able to think about this a bit and figure it out now. Any more questions just ask |
2.I still don't understand, which parentheses are you referring too? they are telling that 1)a=a*--b+c ; 2)a=a*(--b+c) ; are equal. |
3.yah it prints out 088 instead of 88, you can try copy to your compiler, isn't it supposed to be 88 |
|
|
|
|
|
|
b = (++a) + (a++) ;