+ 2

Pre increment int a=1; X=(++a)+(++a)+(++a); Answer is

2nd Feb 2018, 4:22 AM
Kiran Dikshit Menon
Kiran Dikshit Menon - avatar
17 ответов
+ 13
These tricky increment games are nice but although they are syntactically correct they must never be used in a code due to undefined behaviors like Ace and Hatsy pointed out. Creators of languages left these kind of syntax legal but a programmer must know it is to avoid.
2nd Feb 2018, 8:44 AM
AZTECCO
AZTECCO - avatar
+ 12
in java , it would be X will be 9 & a will be 4 //btw what u mean by answer ? //X = 2 + 3 + 4
2nd Feb 2018, 8:15 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
2nd Feb 2018, 5:35 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
a is not defined
2nd Feb 2018, 4:28 AM
Abdurrahman Abulgasim
Abdurrahman Abulgasim - avatar
+ 1
because A and a are different
2nd Feb 2018, 4:28 AM
Abdurrahman Abulgasim
Abdurrahman Abulgasim - avatar
+ 1
int a
2nd Feb 2018, 4:31 AM
Kiran Dikshit Menon
Kiran Dikshit Menon - avatar
+ 1
what is the programming language are you using?
2nd Feb 2018, 4:32 AM
Abdurrahman Abulgasim
Abdurrahman Abulgasim - avatar
+ 1
c++
2nd Feb 2018, 4:32 AM
Kiran Dikshit Menon
Kiran Dikshit Menon - avatar
+ 1
it should be 3 I think
2nd Feb 2018, 4:32 AM
Abdurrahman Abulgasim
Abdurrahman Abulgasim - avatar
+ 1
it should be 3 I think
2nd Feb 2018, 4:33 AM
Abdurrahman Abulgasim
Abdurrahman Abulgasim - avatar
+ 1
but in pc it displaying 4 i get confused
2nd Feb 2018, 4:33 AM
Kiran Dikshit Menon
Kiran Dikshit Menon - avatar
+ 1
so @Ace answer should be right
2nd Feb 2018, 4:34 AM
Abdurrahman Abulgasim
Abdurrahman Abulgasim - avatar
+ 1
ple explain how it works
2nd Feb 2018, 4:34 AM
Kiran Dikshit Menon
Kiran Dikshit Menon - avatar
0
compiler dependent.But for sake of answer apply right associativity
11th Jun 2018, 9:27 AM
Dhanaraj S
Dhanaraj S - avatar