+ 4
why come this output ==10? int x=3; x= ++x + ++x; cout<<x;
4 Antworten
+ 4
The compiler will pre-increment the value of x twice and then add. Therefore, 5+5
+ 1
twice increament of X will make the value of ++x=5
then x=++x + ++x=10
+ 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
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 .