+ 4

why come this output ==10? int x=3; x= ++x + ++x; cout<<x;

13th Jun 2016, 1:44 PM
Lekhraj Singh
Lekhraj Singh - avatar
4 Respostas
+ 4
The compiler will pre-increment the value of x twice and then add. Therefore, 5+5
13th Jun 2016, 1:53 PM
Abhishek Saxena
Abhishek Saxena - avatar
+ 1
twice increament of X will make the value of ++x=5 then x=++x + ++x=10
13th Jun 2016, 2:20 PM
Utpal Kumar
Utpal Kumar - avatar
+ 1
yea it is pre-increment it increments the value before execution. so it will increment the value twice first and then execute it. so it becomes 4 first then 5, now the value of x is 5+5==10
14th Jun 2016, 6:04 AM
Vivek Sharma
Vivek Sharma - avatar
0
There is a rule that expalin that a variable can not be upadated twice in an expression. if such things happen the result depends upon the implementation of that specific compiler .
20th Jun 2016, 1:11 AM
Utpal Kumar
Utpal Kumar - avatar