Consider the following array declaration in ‘C’ language: int array[] = {2, 3, 4, 5}; What will be the output of the following statement? printf("%d", 2[array]);

Consider the following array declaration in ‘C’ language: int array[] = {2, 3, 4, 5}; What will be the output of the following statement? printf("%d", 2[array]); Correct Answer 4

Key Points

 An array is defined as the collection of similar types of data items stored at contiguous memory locations. Arrays are the derived data type in C programming language which can store the primitive type of data such as int, char, double, float, etc. C array is beneficial if you have to store similar elements.

int array = {2, 3, 4, 5}; This array storage be like, 

, i, *(a+i) or *(i+a) all the above representations all are equal and gives the i th index value.

printf(%d', 2); So, it gives the 2nd  index value. i.e 4.

Hence the correct answer is 4.

Additional InformationProgram: 

#include <stdio.h>
int main()
{
    int arr = { 2, 3, 4, 5 };
    printf("%d ",arr);
    printf("%d ",2);
    printf("%d ",*(2+arr));
    printf("%d ",*(arr+2));
    return 0;
}

Output: 4 4 4 4

So above given 2nd index value is 4 for all above print statements.

Related Questions

Comment on the following 2 C programs.
#include  //Program 1int main(){ int a; int b; int c;}#include  //Program 2int main(){ int a; { int b; } { int c; }}