Skip to main content
added 19 characters in body; edited title
Source Link
phant0m
  • 17k
  • 6
  • 52
  • 84

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

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; } 

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

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; } 

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

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; } 
Source Link
Alexandre
  • 5.2k
  • 7
  • 33
  • 39

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

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; }