Multiple choice

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

  1. 6

  2. 5

  3. 4

  4. 0

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

The prefix increment operator ++a increments a BEFORE using its value. Since a is 5, ++a makes it 6 and then returns 6 to cout. The output is 6. Option A is correct. The difference between ++a (prefix) and a++ (postfix) is that prefix increments first, then returns the new value, while postfix returns the old value first, then increments.