0
Why is the ouput b= ++a + ++a equals to 8?
5 Answers
+ 4
a is a reference to a "single" value.
Pre-increment operator changes the value first, before the value is used in an expression.
Therefore the 2 ++a increments was performed first, changing the value of a to 4. And the expression then reads:
b = 4 + 4.
b=8.
+ 2
Can we have the full code please?
+ 2
b = ++a + ++a
there are 2 increments '++' so 'a' is now 4:
b = 4 + 4
b = 8
+ 1
int a=2;
int b= ++a + ++a;
printf("%d",b);
0
Thankyou!