+ 1
Address of array
To print the address we don't use & in printf for strings. Do we use & in printf for array to print the address of array?
8 Respuestas
+ 5
Address of first element is the address of the array.
If you won't dereference, you'll get the addresses of each element of array.
In Jay Matthews code,
'a' refers to the address of first index of array and also the address of array.
+ 4
~ swim ~
I ran this code,
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
printf("Sizeof arr: %d\n", sizeof(arr));
printf("Array address: %d\n", arr);
printf("Sizeof arr: %d\n", sizeof(arr));
return 0;
}
This code didn't produce undefined behavior and the array too didn't decay. Then how Jay Matthews code will produce undefined behavior?
Or maybe I misunderstood you.
Correct me if I am wrong :)
+ 4
Now I understand why the behavior will be undefined.
Which format specifier should we use to get the array address or is there any other way around?
+ 4
Yeah I see but %x should also be not used as it is used for printing unsigned int in hex value.