Multiple choice

What will be the output of the given program? #include<iostream.h> void main ( ) { int a=1; for(;;) { cout<< a++; if(a>10) break; } }

  1. The condition in the for loop is must.

  2. The two semicolons should be dropped.

  3. The for loop should be replaced by a while loop.

  4. No error

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The for loop syntax 'for(;;)' is valid C++ for creating an infinite loop - all three parts (initialization, condition, increment) are optional. The loop continues until the break statement executes when a exceeds 10. The code will print 1 through 10. Option D correctly states there is 'No error'. The loop works as written, incrementing a and breaking when a > 10. Note: The header has 'iostream.h' which is pre-standard C++; modern C++ uses .