Examveda
Examveda

What will be printed after execution of the following code?
void main()
{
      int arr[10] = {1,2,3,4,5};
      printf("%d", arr[5]);
}

A. Garbage Value

B. 5

C. 6

D. 0

E. None of these

Answer: Option D

Solution(By Examveda Team)

When an array is partially initialized at the time of declaration then the remaining elements of the array is initialized to 0 by default.


This Question Belongs to C Program >> Arrays And Strings

Join The Discussion

Comments ( 3 )

  1. Amit Verma
    Amit Verma :
    1 year ago

    And the return type of main is int by default not void.

  2. Amit Verma
    Amit Verma :
    1 year ago

    It will be garbage value according to GCC compiler

  3. Utsav Patel
    Utsav Patel :
    3 years ago

    What will be printed after execution of the following code?
    void main()
    {
    int a[5]={2,4,8};
    printf(“%d”,a[5]);
    }

Related Questions on Arrays and Strings