I did read the usage of memset on msdn and on cplusplus.com, I know that(please correct me if im wrong):
int p =3;
// p = object value
// &p = memory address where p is stored
so what is the difference of:
char szMain[512];
memset( szMain, 0x61, sizeof( szMain ) );
cout << szMain[4];
and:
char szMain[512];
memset( &szMain, 0x61, sizeof( szMain ) );
cout << szMain[4];
(0x61 = a, ASCII table hex)
why both have same behavior? Please forgive me if this isn’t a constructive question.
I’m somewhat of a newbie on c++ and i can’t seem to understand.
szMainis the identifier of an array. In most contexts, array identifiers decay to become a pointer to the first element in the array, in other words&szMain[0].So in your first example, you’re passing
memsetthe address of the first element of the array. In the second example, you’re passing it the address of the array itself. However, these are exactly the same address.