pre decrement | Sololearn: Learn to code for FREE!

+1

pre decrement

what is the output can anyone explain! int a=10, b; b= --a + --a; printf ("%d", a); printf ("%d", b);

9/10/2021 11:58:43 AM

Saran M

8 Answers

New Answer

+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

Saran_37 https://www.sololearn.com/learn/Java/2141/?ref=app https://www.sololearn.com/learn/CPlusPlus/1610/?ref=app https://www.sololearn.com/learn/5357/?ref=app

0

Answer is 8 and 16