0
#include <stdio.h> int main() { int n=0,m; for(m=1;m<=n+1;m++) printf("%d%d",++m,m++); return 0; }
Anyone trace the code and explain it's working .
3 Respuestas
0
Abhishek Thakur
Loop runs only once since
initially n=0 and
m=1 and m<=n+1=>1<=0+1 => 1<=1 is true so prints ++m, m++ so 22 outputs,(hoping evaluating from left to right), then next m++ cause m=4 but m<=n+1 => 4<=1 is false so loop stops..
But actually,
It may print 2 3 or 2 2 or 3 2 or 1 3 or 3 1 because of sequence point issue.. You can see in warnings..
Hope it helps...
edit:
It outputting 31 but it is undefined. on different compiler, it may give different result..
about pre/post increment: refer this.
https://www.sololearn.com/Discuss/1690694/?ref=app
about sequence point issue:
https://en.m.wikipedia.org/wiki/Sequence_point
&
https://www.sololearn.com/Discuss/2038766/?ref=app
hope these helps...
0
Still i didn't get how that increment will give 3 ?
0
It's there happening from left to right so m=1 then
m++ print 1 , after this m=2
++m cause m=3 then it print m value 3. So outputs 3 1