Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

C | Arrays | Question 10

  • Difficulty Level : Hard
  • Last Updated : 28 Jun, 2021

Predict output of following program

Take a step-up from those "Hello World" programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.




int main()
{
    int i;
    int arr[5] = {1};
    for (i = 0; i < 5; i++)
        printf("%d ", arr[i]);
    return 0;
}

(A) 1 followed by four garbage values
(B) 1 0 0 0 0
(C) 1 1 1 1 1
(D) 0 0 0 0 0


Answer: (B)

Explanation: In C/C++, if we initialize an array with fewer members, all remaining members are automatically initialized as 0.

For example, the following statement initializes an array of size 1000 with values as 0.

     int arr[1000] = {0};  


Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!