Open In App
Related Articles

C | Arrays | Question 10

Improve Article
Improve
Save Article
Save
Like Article
Like

Predict output of following program




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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Similar Reads