Examveda
Examveda

What will be the output of the program?
#include<stdio.h>
int main()
{
    int arr[1] = {10};
    printf("%d", 0[arr]);
    return 0;
}

A. 1

B. 0

C. 10

D. 6

E. None of these

Answer: Option C

Solution(By Examveda Team)

>> int arr[1]={10}; The variable arr[1] is declared as an integer array with size '2' i.e. arr[0] and arr[1] and it's first element is initialized to value '10'(means arr[0]=10)
and arr[1] = garbage value or zero
>> printf("%d", 0[arr]); It prints the first element value of the variable arr.

Hence the output of the program is 10.


This Question Belongs to C Program >> Arrays And Strings

Join The Discussion

Comments ( 2 )

  1. Moin Khan
    Moin Khan :
    6 years ago

    #include
    int main()
    {
    int arr[1] = {10}; // ={10,0);
    printf("%d", 0[arr]); // *(arr+0)=arr[0]=10;
    return 0;
    }
    output: 10
    #include
    int main()
    {
    int arr[1] = {10};
    printf("%d", 1[arr]); // if *(arr+1)=arr[1]=0
    return 0;
    }
    output: 0

  2. Agnes Pious
    Agnes Pious :
    7 years ago

    how can the size be 2?
    even if size is 2 then elements are arr[0]=0
    arr[1]=10
    so first element should be 0

Related Questions on Arrays and Strings