2 2 votes int x=0,i; for(i=0;i<10;i++) if(i%2&&x++) x=+2; what is the value of x. Programming in C + – Chandra Bhushan Kuma 2.1k views answer comment Share Follow Print See all 2 Comments 2 2 Comments reply Sandip Shaw commented Dec 12, 2015 i reshown by Sandip Shaw Dec 12, 2015 reply Follow flag 15? 0 0 replyShare Umang Raman commented Dec 21, 2015 reply Follow flag question is x=+2 or x+=2? 1 1 replyShare Please log in or register to add a comment.
Best answer 8 8 votes x should be equal to 13. when i=0; x++ and if would not get executed. when i=1; x++ gets executed, but value of x would increment after that statement so the if would not get evaluated. So, i=0 x=0 i=1 x=1 i=3 x=4 i=5 x=7 i=7 x=10 i=9 x=13 when i is even i%2 is false. x=13 is the answer. monanshi answered Dec 12, 2015 • selected Jul 3, 2017 by monanshi monanshi comment Share Follow See all 2 Comments 2 2 Comments reply worst_engineer commented Dec 21, 2015 reply Follow flag great answer.. so simple , yet i was missing out that trivial if(x++) part. 0 0 replyShare arch commented Aug 24, 2017 reply Follow flag i didnot get it, as ++ has higher precedence then x will be incremented first the value will be checked? please clear my doubt 0 0 replyShare Please log in or register to add a comment.