How integers in VC++ 2012 are stored in memory on windows

This article is written by Luke(Parthas.Menethil.Sun). All rights reserved.

When we assign an integer to a variable, in fact, we store that number in some standard format into our memory somewhere. I have always been curious about how they are stored into our memory. Let’s check it out here.

Based on different languages, compilers, compiling configurations and systems, the answer may be various. My environment is using Visual Studio 2012 with the CL 17.00.51106.1 for x86 complier on Windows 7.

My testing code is simple:

#include
int main(){
	int i = 0x12ABCDEF;   // Assign a hexadecimal number
	printf("%x", &i);     // Get the memory address of that variable
	return 0;
}

First I assign a number to fill all bytes of the integer and output its memory address.

While running, we can use hex editors like WinHex to monitor what’s going on in the memory.

We can see at the specific offset, the variable in each byte is stored in the reverse order.

Leave a Reply

Your email address will not be published. Required fields are marked *