Which of the following will correctly initialize an array of 3 integers?

20232025

Which of the following will correctly initialize an array of 3 integers?

  1. A.

    int arr[3] = {1, 2};

  2. B.

    int arr[2] = {1, 2, 3};

  3. C.

    int arr[3] = {1, 2, 3};

  4. D.

    int arr[4] = {1, 2};

Attempted by 954 students.

Show answer & explanation

Correct answer: C

The correct syntax to declare and initialize an array in C is data_type array_name[size] = {element1, element2, ...}. In option C, the array is both declared as holding 3 elements and initialized with those 3 elements, making it the correct choice.

Explore the full course: Cocubes Preparation