What will be the output of the following C++ code?

int arr[] = {10, 20, 30};
int *p = arr;
cout << *(p + 1);
                        

Options

  • A. 10
  • B. 20
  • C. 30
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. 20

Detailed Explanation

Answer: (B) 20

For an array, the name arr can be used as a pointer to its first element.

Therefore, p initially points to arr[0].

The expression p + 1 points to the next array element, which is arr[1].

Therefore, *(p + 1) gives the value 20.