in Programming in C
394 views
0 votes
0 votes

#include <stdio.h>

 int main()

{   

   int *a[] = {0,1,2,3,4};

 

    printf("arr0=%d\n", a+0) ;

    printf("arr1=%d\n", a+1);

    printf("arr2=%d\n", a+2);

    printf("arr3=%d\n", a+3);

    printf("arr4=%d\n", a+4);

    printf("again \n" ) ;

    printf("arr0=%d\n", *a+0);

    printf("arr1=%d\n", *a+1); 

    printf("arr2=%d\n", *a+2);

    printf("arr3=%d\n", *a+3); 

    printf("arr4=%d\n", *a+4); 

 

    return 0;

}

The output is
arr0=1123688464
arr1=1123688472
arr2=1123688480
arr3=1123688488
arr4=1123688496
again 
arr0=0
arr1=4
arr2=8
arr3=12
arr4=16
Please Explain 
in Programming in C
394 views

8 Comments

 int *a[] = {0,1,2,3,4};

check it.....it should be as

 int (*a)[] = {0,1,2,3,4};

0
0
int (*a)[] = {0,1,2,3,4}; //compilation failed
and
 int *a[] = {0,1,2,3,4}; //compilation successful
0
0

 int *a[] = {0,1,2,3,4};  ===> a is a array of pointers, but you are giving integers

but i don't know, why this statement giving warning only.

coming to

int (*a)[] ;  ====> a is a pointer to array

we use this statement like

int p[]={0,1,2,3,4};

int (*a)[]=&p;

yes i agree,

 int (*a)[] = {0,1,2,3,4};

is also not correct due to we have to pass the address of the array but not the array

0
0
thanks for correcting me......

but why in output there is  8 byte difference in each address ..it must be 4 bytes......
0
0

but why in output there is  8 byte difference in each address ..it must be 4 bytes......

in which code?

0
0
the code given in problem
0
0
i didn't know,
0
0
ok ... thanks
0
0

Please log in or register to answer this question.

Related questions