C: How come an array's address is equal to its value?

Posted by Alexandre on Stack Overflow See other posts from Stack Overflow or by Alexandre
Published on 2010-03-27T05:59:56Z Indexed on 2010/03/27 6:03 UTC
Read the original article Hit count: 335

Filed under:
|
|

In the following bit of code, pointer values and pointer addresses differ as expected.

But array values and addresses don't!

How can this be?

Output

my_array = 0022FF00
&my_array = 0022FF00
pointer_to_array = 0022FF00
&pointer_to_array = 0022FEFC

...

#include <stdio.h>

int main()
{
  char my_array[100] = "some cool string";
  printf("my_array = %p\n", my_array);
  printf("&my_array = %p\n", &my_array);

  char *pointer_to_array = my_array;
  printf("pointer_to_array = %p\n", pointer_to_array);
  printf("&pointer_to_array = %p\n", &pointer_to_array);

  printf("Press ENTER to continue...\n");
  getchar();
  return 0;
}

© Stack Overflow or respective owner

Related posts about c

    Related posts about array