0
Please explain the output.
int main() { int a=20; ++a; int b=a; ++b; if(b>a){ cout <<++a; } else{ cout <<--a; }
5 Réponses
+ 2
note that if it is : cout << a++;
output : 21
because in this case the compiler will print 'a' value then increase its value by 1.
good luck!
+ 1
I will explain line by line what happen
a=20
++a : a==21
int b=a : b==21
++b : b==22
b>a : true
cout<<++a is the same as
++a : a==22
cout<<a : display a
as it is pre incrementation
+ 1
++a means a is now 21, b = a means b is also 21 now, ++b means b is 22 and 22 > 21 so it enters the if statement and outputs 22 (because a which is 21 gets incremented again)
+ 1
Thanks for the answer both of u 👍👍
+ 1
You're welcome :)