C Programming - Arrays - Discussion

Discussion Forum : Arrays - Find Output of Program (Q.No. 8)
8.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    int arr[1]={10};
    printf("%d\n", 0[arr]);
    return 0;
}
1
10
0
6
Answer: Option
Explanation:

Step 1: int arr[1]={10}; The variable arr[1] is declared as an integer array with size '2' and it's first element is initialized to value '10'(means arr[0]=10)

Step 2: printf("%d\n", 0[arr]); It prints the first element value of the variable arr.

Hence the output of the program is 10.

Discussion:
17 comments Page 2 of 2.

Noel said:   7 years ago
I think there is an error, arr[1], initializes an array with only 1 element, not two.

Rupinder said:   1 decade ago
Here 0 acts as a pointer pointing to zeroth element of an array named arr.

Geetha said:   1 decade ago
Yes. If it is arr[1]=10; (without brackets) means arr[0]=0 and arr[1]=10.

Nitin singh chouhan said:   7 years ago
I am getting this output is 1010 why?

Prakash said:   8 years ago
Yes, arr[i] and i[arr] is same.

Vikarm G said:   1 decade ago
Yes, the array is of size '1'

Raji said:   8 years ago
Is arr[i] and i[arr] same?


Post your comments here:

Your comments will be displayed after verification.