I'm a Java developer with very little knowledge of pointers. I have the following C++ code (that someone else wrote) that I'm trying to understand:
ULONGLONG passedValue;
BYTE myArr[16];
memset(myArr, 0x00, sizeof myArr);
*((ULONGLONG *) myArr) = passedValue;
While I understand that the memset method call fills up the myArr byte array (of size 16) with 0s, I'm not sure what the last line does.
According to MSDN, ULONGLONG is 8 bytes...whereas myArr is 16 bytes. What will be in myArr after the last statement is executed?
This term
(ULONGLONG *) myArrwill convert myArr to a pointer to ULONGLONG type.Then,
*((ULONGLONG *) myArr)is the value of where the pointer is pointing to.And,
assigns
passedValueto the first 8 byte ofmyArr BYTEarray.