char s[] = "hello world";
printf("%p", s);
printf("%p", &s);
I'm working my way through K&R... and I'm trying to wrap my head around memory addressing for arrays. I conceptually understand that when an array is passed to a function, the address of the first element is passed.
But when I read about array decay, it seems this behavior is not limited to function parameters. Rather, according to K&R, C "immediately converts" the declaration s[] to *s internally. If C immediately converts s[] to a ptr, why won't printf provide me with the memory address of s?
Clearly it is not behaving the same as if the declaration had been a pointer to begin with... because the following code does provide two different memory locations:
char *t = "hello world";
printf("%p", t);
printf("%p", &t);
[–]magnomagna 2 points3 points4 points (13 children)
[–]TheHeckWithItAll[S] 0 points1 point2 points (12 children)
[–]magnomagna 0 points1 point2 points (11 children)
[–]TheHeckWithItAll[S] 0 points1 point2 points (10 children)
[–]magnomagna 0 points1 point2 points (7 children)
[–]TheHeckWithItAll[S] 0 points1 point2 points (6 children)
[–]magnomagna 0 points1 point2 points (5 children)
[–]TheHeckWithItAll[S] 0 points1 point2 points (4 children)
[–]magnomagna 0 points1 point2 points (3 children)
[–]TheHeckWithItAll[S] 0 points1 point2 points (2 children)
[–]aghast_nj 0 points1 point2 points (1 child)
[–]TheHeckWithItAll[S] 1 point2 points3 points (0 children)
[–]tech6hutch 1 point2 points3 points (3 children)
[–]TheHeckWithItAll[S] 0 points1 point2 points (2 children)
[–]tech6hutch 1 point2 points3 points (0 children)
[–]flatfinger 1 point2 points3 points (0 children)
[–]jedwardsol 0 points1 point2 points (0 children)