What's the output? Why is 10 and 0? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What's the output? Why is 10 and 0?

include <stdio.h> int main() { int var1, var2; var1=10; var2=10; var2= 2*(++var1)-2*(--var1); printf(" Var1= %d \n Var2= %d",var1,var2); return 0; }

26th Mar 2019, 8:56 AM
Gab
Gab - avatar
2 Answers
+ 3
Gabbro Your syntax is wrong and every answer that tries to explain why the output is 10 and 0 is wrong as well. Changing the value of a variable more than once in the same expression will lead to undefined behavior. The values might be 10 and 0 with your compiler and on your platform and they might be totally different under other circumstances. It's not defined what happens when you use an expression like the one in your question
26th Mar 2019, 2:02 PM
Anna
Anna - avatar
+ 1
Var1 =10 Var2 = 0 For priority observance
26th Mar 2019, 9:44 AM
mohsen arman manesh
mohsen arman manesh - avatar