1 votes 1 votes int main(){ int a[5]={1,2,3,4,5}; char *str="hello"; printf("%p %p",a,&a); printf("%p %p",str,&str); } Why in $1$st printf , both the outputs are same($a$,&$a$) And in $2$nd printf ,both the outputs are different(str,&str) please help! Programming in C programming-in-c + – Learner_jai asked Mar 17, 2017 • edited Mar 18, 2017 by dd Learner_jai 484 views answer comment Share Follow See 1 comment See all 1 1 comment reply Akriti sood commented Mar 17, 2017 reply Follow Share because array name is itself address of the array i.e it is a pointer,so a and &a is same. wheras str is not a character array,it prints the address of the string i.e 'hello' wheras &str givess the address of the 'str' which is a character pointer.hence they are diff 5 votes 5 votes Please log in or register to add a comment.
Best answer 3 votes 3 votes $a$ is an array . $a$ decays to the address of the first element of a[] , i.e. a decays to a pointer of type int*. (pointer to an integer) &$a$ is also a pointer having the same numerical value of &$a$[$0$], but &$a$ has different type , int (*) [5] This difference comes into picture when we do the pointer arithmetic as shown in the above image. str and string literal "hello" has different storage location in memory. str is a pointer of char* type and stores the starting address of "hello" But str has its own address ,i.e. &str , type is pointer to a character pointer. Some pointer arithmetic is also shown in above image. dd answered Mar 18, 2017 • selected Mar 18, 2017 by Learner_jai dd comment Share Follow See all 0 reply Please log in or register to add a comment.