Multiple choice

What is the output of the following code snippet?

#include <iostream> using namespace std; int main () { int numbers[5]; int * p; p = numbers; *p = 10; p++; *p = 20;
p = &numbers[2]; *p = 30;
p = numbers + 3; *p = 40;
p = numbers; *(p+4) = 50;
for (int n=0; n<5; n++) cout << numbers[n] << , ; return 0; }

  1. 10, 20, 30

  2. 10, 20, 30, 40

  3. 10, 20, 30, 40, 50

  4. None of the above

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

A very simple concept has been used in this program, i.e. name of array basically contains base address and here we are initializing pointer to base address and then setting and incrementing pointer. Therefore, the correct answer is 10, 20, 30, 40, 50.