Which declaration correctly creates a two-dimensional integer array with 3 rows and 4 columns in C++?

Options

  • A. int a[3][4];
  • B. int a[4][3];
  • C. int a[3,4];
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. int a[3][4];

Detailed Explanation

Answer: (A) int a[3][4];

A two-dimensional array can be thought of as an array of arrays.

The declaration:

int a[3][4];

creates an array containing 3 rows and 4 columns.

The total number of integer elements is:

3 × 4 = 12

An element can be accessed using two indexes, for example a[1][2].