Multiple choice

What is the output of the following C++ code?

#include <iostream> using namespace std; int main () { int a; for (a = 1; a <= 1; a++) cout << a++; cout<< <<a; return 0; }

  1. 1 1

  2. 1 2

  3. 1 3

  4. 1 4

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

As shown in the code, i is incremented two times. In first cout, 1 will be displayed and in second cout -since a is incremented twice by then, 3 is displayed. Hence, 1 3 is the correct output.