Which declaration is valid for a 2D array in C?
- Aint arr[2][2] = {1,2,3,4};
- Bint arr[2,2] = {{1,2}, {3,4}};
- Cint arr[][] = {{1,2}, {3,4}};
- Dint arr[][] = {1,2,3,4};
Correct answer: A
Explanation
int arr[2][2] = {1,2,3,4}; is valid, since C fills the array row-wise. A missing first dimension is allowed only when initialised, and the other dimension must always be specified. Discussion 0
Nobody has replied yet. Start the discussion!