I stumbled upon this odd result when I was messing around with C arrays:
char s[100] = "hello";
if(s == &s[0]) printf("true. ");
if(s == &s) printf("true.");
// output: true. true.
I know that s
holds the memory location of the first element, but is there a way to find the address of s
(the address of the pointer that points to the first element)? Why does &s
equal s
? Not that this is useful, but I'd like to know what's going on under the hood.
I'm not sure if different compilers implement it differently, but I am using gcc.