0

Why the output of this code is 16?

Int a=2, b, c; b=++a; c=++b; a=b*c; Cout<<a;

12th Nov 2017, 9:28 PM
Feed_ls
Feed_ls - avatar
3 Answers
- 1
I understood))
12th Nov 2017, 9:32 PM
Feed_ls
Feed_ls - avatar
+ 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.
12th Nov 2017, 10:06 PM
Yukinori Shinohara
Yukinori Shinohara - avatar
0
preincrement
12th Nov 2017, 9:54 PM
Andika Romansyah