Which of the following correctly declares an array in C++?

2023

Which of the following correctly declares an array in C++?

  1. A.

    array{10};

  2. B.

    int array;

  3. C.

    int array[10];

  4. D.

    More than one of the above

  5. E.

    None of the above

Attempted by 1532 students.

Show answer & explanation

Correct answer: C

In C++, an array is declared using the syntax: data_type array_name[size]; Step 1: The data type (e.g., int, float) must be specified. Step 2: The array name follows the data type. Step 3: The size of the array is specified in square brackets []. Now, evaluate each option: Option A: 'array{10};' — Uses curly braces instead of square brackets and missing data type. Incorrect. Option B: 'int array;' — Declares a single variable, not an array. Missing size in brackets. Incorrect. Option C: 'int array[10];' — Correct data type, name, and size in square brackets. Valid array declaration. Option D: 'More than one of the above' — Only one option is correct, so this is incorrect. Option E: 'None of the above' — Since Option C is correct, this is incorrect.

Explore the full course: Up Lt Grade Assistant Teacher 2025