What is the output of the following C++ code?
x = 5; y = 30;
while (x <= y)
x = x * 2;
cout << x << " " << y << endl;
Step 1:
x=5 y=30
x=5*2
x=10 y=30
Step 2:
10<=30 (true)
x=10*2
x=20 y=30
Step 3:
20<=30 true
x=20*2
x=40 y=30
Step 4:
40<=30 false
Break loop
Result:
this code output
x=40 y=30
Comments
Leave a comment