0

Question about --

int a=20, b = 20; printf("%d\t%d\t%d\n", ++a, a++, --a);//why --a is 21 printf("%d\t%d\t%d\n", ++b, b++, b--);//but b-- is 20?

24th Sep 2019, 9:23 AM
♥️ Ali M ♣️
♥️ Ali M ♣️ - avatar
2 Réponses
+ 2
Avoid mixing data access and modification in a single execution point. Output of that code depends on compiler implementation. Output in one compiler may differ from that of another.
24th Sep 2019, 10:07 AM
Ipang
0
You need to familiar about Pre and Post increment/decrement in C ++X = It means it increment the initialised value of x by 1 then use in any other expression X++ = It means it use value of x in expression then increment it by 1 --X = It means it decrement the value of x by 1 then uses it in any equation. X-- = It means it uses the value of x by in any equation then decrement the value of X I hope it helps, and you get the output of your code.
24th Sep 2019, 9:55 AM
Chirag Kumar
Chirag Kumar - avatar