c++windowsconsolevisual-studio-2022

How come in Visual Studio 2022 the sizeof unsigned long is 4 bytes and not 8 bytes?


When initializing the values ​​in an array of long values, I noticed that the sizes were 4 bytes and not 8 bytes in the values.

sizeof(unsigned long) shows as 4 bytes:

enter image description here

The same value is shown in both 32-bit and 64-bit versions.

Version:
Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.12.4


Solution

  • This seems correct, following the table found on the Data Type Ranges Microsoft documentation page.

    unsigned long (same type as unsigned long int) is 4 bytes, while unsigned long long (same type as unsigned __int64 is 8 bytes.