C | Arrays | Question 12

filter_none

edit
close

play_arrow

link
brightness_4
code

#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;
}

chevron_right


(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



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.