Good day! I am trying to learn how to allocate memory dynamically using winapi.
{ HANDLE hHeap = GetProcessHeap(); TCHAR *strName = (TCHAR*)HeapAlloc(hHeap, 0, 1 * sizeof(TCHAR)); lstrcpy(strName, _T("Hello")); MessageBox(0, strName, 0, 0); HeapFree(hHeap, 0, strName); } The problem is that I don’t understand why this code works normally .. It seems like I allocate memory for 1 character, but I bring 5 characters there (this is not including the terminating zero), moreover, even if I instead of 1 * sizeof (TCHAR ) I will write 0, it also works and gives a full Hello. Explain how it works? Are there any other non-related threads in this code? Thank.