C Quiz – 111 | Question 3

Pick the best statement for the below:

filter_none

edit
close

play_arrow

link
brightness_4
code

int arr[50] = {0,1,2,[47]=47,48,49};

chevron_right


(A) This isn’t allowed in C and it’ll give compile error
(B) This is allowed in C as per standard. Basically, it’ll initialize arr[0], arr[1], arr[2], arr[47], arr[48] and arr[49] to 0,1,2,47,48 and 49 respectively. The remaining elements of the array would be initialized to 0.


Answer: (B)

Explanation: In C, initialization of array can be done for selected elements as well. By default, the initializer start from 0th element. Specific elements in array can be specified by []. It should be noted that the remaining elements (i.e. the ones not mentioned in array initialization) would be initialized to 0. For example, “int arr[10] = {100, [5]=100,[9]=100}” is also legal in C. This initializes arr[0], arr[5] and arr[9] to 100. All the remaining elements would be 0.

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.