in Programming in C edited by
793 views
1 vote
1 vote
int main()
{
    int i=-1, j=-1,k=0,l=2,m;
    m= i++ && j++ && k++ || l++ ;
    printf("%d %d %d %d %d", i,j,k,l,m);
    return 0;
}
in Programming in C edited by
793 views

4 Comments

edited by
i=0, j=0, k=1, l=3, m=1
...drawing parse tree and following short circuting rule will give above answer..
1
1
Please elaborate..
0
0

1. All are post increment. so first value will assigne then increment the value

2. All non zero value will be considered as true.

3. Because of K, L will also get checked.

So at last after increment output we will get as:

       0 0 1 3 1

0
0
Only 0 0 1 3 will be printed, since there are only 4 %d in the printf call.
0
0

2 Answers

0 votes
0 votes
i=0, j=0, k=1, l=3, m=1

2 Comments

Yeah.. I am getting same

0 0 1 3 1 is correct

Thanks
0
0
y j = 0

its and operation so when it runs i++ so it will read i value -1 so negative no. consider as false now j and k will not be evaluated and l value will be checked so ans should be

0 -1 0 3 1

please correct where i am wrong
0
0
0 votes
0 votes

....