Possible Duplicate:
C: How come an array's address is equal to its value?
I recently found code in my project that calls memcpy
with the address of array name
int a[10];
memcpy(&a, &b ,sizeof(a));
Surprisingly (to me) it seems to work.
Should I change it to memcpy(a,b,sizeof(a));
?
Is it allowed by the C++ spec? Can anyone point me to resource about this behavior? Are there any pitfalls?
I also checked
assert((void*)&a == (void*)a);
and &a
indeed is the same as a
(besides it's type).
I verified this behavior in VS2005, VS2008 and VS2010.