Skip to content
Related Articles

Related Articles

C Quiz – 112 | Question 2
  • Difficulty Level : Medium
  • Last Updated : 02 Nov, 2015

Pick the best statement for the below program snippet:




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

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 :