What's the output?

Jun 20, 2012 at 2:42am
What is the output of the following C++ code?
My answer was "d" (that is 10) because is my understanding that for a while loop to execute the expresion must evaluate to "true" and in this case the expresion num > 10 is false because num=10.

Please correct me if I'm wrong and again please check if the syntax it's OK

Thanks


num = 10;

while (num > 10)

num = num - 2;

cout << num << endl;

a. 0
b. 6
c. 8
d. 10
Jun 20, 2012 at 2:56am
I agree with your analysis.
Jun 20, 2012 at 8:25am
What is the answer?
Jun 20, 2012 at 8:36am
yes num cannot be greater than ten unless you use this operator >= so your answer is true
Topic archived. No new replies allowed.