+ 1
pre decrement
what is the output can anyone explain! int a=10, b; b= --a + --a; printf ("%d", a); printf ("%d", b);
7 odpowiedzi
+ 3
It will print 8 & 17
+ 3
What you are seeing here is undefined behaviour ( or more appropriately an implementation defined behaviour ) because your program is changing value of "a" multiple times between 2 sequence points.
Such constructs are are forbidden in C/C++ as output of such programs can't be predicted and would vary depending on the language implementation you are using.( in most of the cases, your compiler should also warn you about the same )
+ 1
Thank u for ur response ..but i got some different answer as 8 and 16....
Please check it out Yahel Saurabh Kumar Yadav
+ 1
Saran_37,
You are right... if anyone knows why- I'd also like to know :)
0
8 and 17.
Pre-decrement decrements the value by 1 and only then does the wanted operation with it.
0
When I run in compiler it shows... 8 and 16 ...can anyone explain
0
Answer is 8 and 16