I'm new to c language. This is my code
char c[]="name";
char *p="city";
printf("\n 1. memory location of array in pointer is %u",p);
p=c;
printf("\n 2. memory location of array in pointer is %u",p);
it gives me output :
memory location of array in pointer is 177
memory location of array in pointer is 65518
now checkout the difference in memory allocation, when first time
char *p="city"
address in p is 177 and second time when
p=&c;
address in p is 65518. why? I didn't get the address allocation to array. Normally when declare some variable in c, there address is something like 655... and at the time char *p, its different. Is there any specific reason for this.
I'm working on windows 7 32 bit operating system
My question is when
char *p="city"
address in p is 177. why?
%p
to print addresses, Secondp = &c;
is not correct assignment, you are ignoring warning..*I didn't get the address allocation to array.
* yes but you are assigning different address top
. – Grijesh Chauhan Feb 8 at 8:11char *str
andchar str[]
and how both are stored in memory – Grijesh Chauhan Feb 8 at 8:12177
and655
make no sense whatsoever as long as you are using%u
to print pointer values.%u
is forunsigned int
values. Use%p
to print pointers. – AndreyT Feb 8 at 17:51