how can I put a INT type variable to a wchar array ?
Thanks
EDIT:
Sorry for the short question. Yes we can cast INT to a WCHAR array using WCHAR*, but when we are retrieving back the result (WCHAR[] to INT), I just realize that we need to read size of 2 from WCHAR array since INT is 4 BYTEs which is equal to 2 WCHARs.
WCHAR arData[20];
INT iVal = 0;
wmemcpy((WCHAR*)&iVal, arData, (sizeof(INT))/2);
Is this the safest way to retrieve back INT value from WCHAR array
Technically, the way you do it is unsafe due to strict aliasing and alignment. The safest and the most portable way would be to read chars one by one and combine them with bit shifts.
While your code would work on a Windows PC, don’t expect it to be portable or work for all compilers and compiler settings.
Basic example (can be improved to be more portable with regard to integer sizes, byte order, etc):