-1

When I declared a variable

char buf[512];

What does mean &buf ?

It seems equals to buf :

printf(" buf :  %p %p\n", (void *) buf, (void *) &buf);

prints :

buf :  0x7ffda6053fe0 0x7ffda6053fe0
Sander De Dycker
  • 16,053
  • 1
  • 35
  • 40
Robert Po
  • 1
  • 2

2 Answers2

0

it is the address of the 1st element in the array (i.e. address of buf[0]) vs. the address of the array itself (i.e. buf). No big surprise that they are equal.

CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
0

The address is the same because an array decays into a pointer to the first element when passed, on the other hand, the address-of operator & takes the address of the array, the address of the first element and the address of the array itself are the same.

Use %p instead of %d to print addresses:

printf(" buf :  %p %p\n", (void *)buf, (void *)&buf);
David Ranieri
  • 39,972
  • 7
  • 52
  • 94