Skip to content
Related Articles

Related Articles

Improve Article

C Quiz – 110 | Question 5

  • Difficulty Level : Easy
  • Last Updated : 28 Jun, 2021

In C, 1D array of int can be defined as follows and both are correct.

int array1D[4] = {1,2,3,4};
int array1D[] = {1,2,3,4};

But given the following definitions (along-with initialization) of 2D arrays

int array2D[2][4] = {1,2,3,4,5,6,7,8}; /* (i) */
int array2D[][4] = {1,2,3,4,5,6,7,8}; /* (ii) */
int array2D[2][] = {1,2,3,4,5,6,7,8}; /* (iii) */
int array2D[][] = {1,2,3,4,5,6,7,8}; /* (iv) */

Pick the correct statements.
(A) Only (i) is correct.
(B) Only (i) and (ii) are correct.
(C) Only (i), (ii) and (iii) are correct.
(D) All (i), (ii), (iii) and (iv) are correct.

Answer: (B)

Explanation: First of all, C language doesn’t provide any true support for 2D array or multidimensional arrays. A 2D array is simulated via 1D array of arrays. So a 2D array of int is actually a 1D array of array of int. Another important point is that array size can be derived from its initialization but that’s applicable for first dimension only. It means that 2D array need to have an explicit size of 2nd dimension. Similarly, for a 3D array, 2nd and 3rd dimensions need to have explicit size. That’s why only (i) and (ii) are correct. But array2D[2][] and array2D[][] are of incomplete type because their complete size can’t derived even from the initialization.

Quiz of this Question

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :