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?
- A.
int arr[3] = {1, 2};
- B.
int arr[2] = {1, 2, 3};
- C.
int arr[3] = {1, 2, 3};
- 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.