Confusing increment operator
int a=10; a = a++ + 10; printf("%d",a); Output Is 20 Please explain how
Siddharth Jain , it is because the post increment "++" operator. Post increment first evaluate the expression then increment it. It's exactly the opposite with pre increment => if you put "++" before the variable - first increment the value and then evaluate the expression. You can change it and you'll see the difference => with pre increment it's 21, post increment it is 20. Hope you understand it better 😉
TheWh¡teCat can u explain this
TheWh¡teCat but what about the increment operator after assignment
It's because the value was assigned to "a" before the increment happened.
a++ is postfix. The postfix form uses the value of the variable first, before incrementing/decrementing it. If you change the code a bit, then an example of incriment postfix a ++ will be more obvious: int a = 10; int b = 0; b = a++ + 10; /* step 1: b=10+10; step 2: a=10+1; */ printf("%d",a); //Output Is 11 printf("%d",b); //Output Is 20 https://www.sololearn.com/learn/C/2917/
I have tried every way I could find but still I can't display my local images ..what am I doing wrong?
Pls rectify the errors.