Skip to content
Related Articles
Open in App
Not now

Related Articles

C Quiz – 112 | Question 2

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 28 Jun, 2021
Improve Article
Save Article

Pick the best statement for the below program snippet: 
 

C




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


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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!