+ 3
#include <iostream> using namespace std; int main() { int x; int i=3; x=++i + i++; cout << x; return 0; }
How the output is 9
3 ответов
+ 1
x=++i + i++;
lets go step by step
first thing is ++i , it increments i's value before its 'used' so
( i=4)
now i+i++
in the second i++, the value will be used first and then be incremented.
i= 4+ 4
= 8
and now will be incremented
= 9
0
sagar is pointing out a malfunction.
Compiler acts differently when using same variable with multiple increments.
Take the following
int x; int i = 3; int j = 4;
x = ++i + j++;
cout <<x;
will give you 8.
0
I too feel compiler acts differently.In some other compiler it would be 8
good question