Skip to content
Related Articles

Related Articles

Improve Article
C Quiz – 111 | Question 3
  • Difficulty Level : Hard
  • Last Updated : 01 Nov, 2015

Pick the best statement for the below:




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

(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

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 :