0
Why the output of this code is 16?
Int a=2, b, c; b=++a; c=++b; a=b*c; Cout<<a;
3 Answers
- 1
I understood))
+ 5
int a, b;
a = 2;
cout << a << endl;
b = ++a;
cout << a << endl;
cout << b << endl;
Output:
2 //A
3 // A
3 // B
By using the ++x prefix on an interger, you also increase the number of the original interger.
B becomes 4 after you assign C with (++B), because the compiler first adds 1 to 3, then assigns B to C.
In other words, A is actually 4 * 4.
If you want B to stay a 3, then use (C = B + 1;), which gives C a number 1 number larger than B's, while keeping B as a 3.
0
preincrement