C Quiz – 112 | Question 2

Pick the best statement for the below program snippet:

filter_none

edit
close

play_arrow

link
brightness_4
code

struct {int a[2];} arr[] = {1,2};

chevron_right


(A) No compile error and it’ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[1].a[0] would be 2.
(B) No compile error and it’ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2. The second element arr[1] would be ZERO i.e. arr[1].a[0] and arr[1].a[1] would be 0.
(C) No compile error and it’ll create array arr of 1 element. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2.


Answer: (C)

Explanation: Since size of array arr isn’t given explicitly, it would be decided based on the initialization here. Without any curly braces, arr is initialized sequentially i.e. arr[0].a[0] would be 1 and arr[0].a[1] would be 2. There’s no further initialization so size of arr would be 1. Correct answer is C.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

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.