Given the following loop….
for (i = 14; i <= 20; i++)
cout << i <<endl;
If i++ were changed to i-- a compile error would result. True OR False. explain
C++
Solution
Answer
False
Explanation
There will be no compilation error but infinite loop occurs
for (i = 14; i <= 20; i++)
cout << i <<endl;
it will give result
14
15
16
17
18
19
20
if you change
for (i = 14; i <= 20; i--)
cout << i <<endl;
it will start print
14
13
12
11
..
it willl go infinite loop and it will print numbers negative numbers also
loop will never stop
But please note it will not give compilation error
but infinite loop occur
Get Answers For Free
Most questions answered within 1 hours.