0

Why is the ouput b= ++a + ++a equals to 8?

22nd Oct 2018, 7:24 AM
Adi Citta Agitsha Justitio
Adi Citta Agitsha Justitio - avatar
5 Antworten
+ 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.
22nd Oct 2018, 8:34 AM
Lowell Basco
Lowell Basco - avatar
+ 2
Can we have the full code please?
22nd Oct 2018, 7:26 AM
jtrh
jtrh - avatar
+ 2
b = ++a + ++a there are 2 increments '++' so 'a' is now 4: b = 4 + 4 b = 8
22nd Oct 2018, 7:54 AM
jtrh
jtrh - avatar
+ 1
int a=2; int b= ++a + ++a; printf("%d",b);
22nd Oct 2018, 7:43 AM
Adi Citta Agitsha Justitio
Adi Citta Agitsha Justitio - avatar
0
Thankyou!
23rd Oct 2018, 5:48 AM
Adi Citta Agitsha Justitio
Adi Citta Agitsha Justitio - avatar