
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<!--formatting fix --> #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; }
More
1 Expert Answer
Shailendra B. answered 05/10/19
Tutor
4.9
(105)
Software technical lead with 28 years experience in Embedded/Linux/C
The name of an array is always equal to the address of its zeroth element. So
int table[20];
table is same as &table[0] and it is same as table + 0
similarly, table + 4 is same as &table[4]
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Carter A.
05/10/19