Q: Which of the following is a correct way to initialize an array?
-
A
int a = {1,2,3};
-
B
int a[3] = 1,2,3;
-
C
int a[3] = {1,2,3};
-
D
int a(3) = {1,2,3};
C
Answer:
C
Explanation:
In C++, an array must be declared with a size and initialized using curly braces { }.
int a[3] = {1, 2, 3};
This statement:
Why other options are wrong
-
A) int a = {1,2,3}; ❌ → a is not an array
-
B) int a[3] = 1,2,3; ❌ → Missing { }
-
D) int a(3) = {1,2,3}; ❌ → Invalid array syntax
Correct Answer: C) int a[3] = {1,2,3};
Related Topic:
Share Above MCQ