Open In App

C Quiz – 110 | Question 5

Like Article
Like
Save
Share
Report

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

C




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


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

C




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
Please comment below if you find anything wrong in the above post


Last Updated : 28 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Similar Reads