Skip to content
Related Articles

Related Articles

C | Arrays | Question 12
  • Difficulty Level : Basic
  • Last Updated : 09 Sep, 2013




#include <stdio.h>
  
int main()
{
    int a[][] = {{1,2},{3,4}};
    int i, j;
    for (i = 0; i < 2; i++)
        for (j = 0; j < 2; j++)
            printf("%d ", a[i][j]);
    return 0;
}

(A) 1 2 3 4
(B) Compiler Error in line ” int a[][] = {{1,2},{3,4}};”
(C) 4 garbage values
(D) 4 3 2 1


Answer: (B)

Explanation: There is compilation error in the declaration ” int a[][] = {{1,2},{3,4}};”.

Except the first dimension, every other dimension must be specified.

int arr[] = {5, 6, 7, 8} //valid

int arr[][5] = {}; //valid

int arr[][] = {}; //invalid

int arr[][10][5] = {}; //valid

int arr[][][5] = {}; //invalid

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 :