| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
General - Logical operator c
#include<stdio.h>
void main() { int i=-3,j=2,k=0,m; m=++||++j&&++k; printf("\n%d%d%d%d",i,j,k,m); } I know ans is -2 2 0 1 but i don't know how it is coming why k is not equal to 1. Somebody help? |
|
#2
|
||||
|
||||
|
I believe you missed an i there?
Let me simplify it for you: x||y&&z Which parses to be the same as x||(y&&z) In this case, since x is non-zero (true), it already knows the expression as a whole will be true. Hence, it doesn't need to evaluate y and z to get the expresssion, even though it has side effects. Note that y (j in your code) is not changed either.
__________________
Quote:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > General - Logical operator c |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|