Review of Pointers and Number Representations

Download the C program located here:

http://15418.courses.cs.cmu.edu/tsinghua2017content/code/pointers.cpp

This C program access a 32-byte buffer in memory that has the same values in memory as shown on this slide in Lecture 1.

There is a comment in the program that asks to to predict the output of the line:

printf("y[0] = %u\n", y[0]);

If you run the code, you'll see that the value of the integer at y[0] is a large number.

y[0] = 4294914080

To understand why this is the case, you'd need to know that an integer is 4 bytes, and that x86 processors (and nearly all processors these days) store variables requiring multiple bytes of memory in "Little Endian" format.

For example, consider a four-byte integer stored at address 0x30. This bits representing the integer fill the following locations in memory: 0x30, 0x31, 0x32, 0x33. In a little Endian system, the low-order byte of a four-byte number stored at address 0x30 is stored at the lowest address in memory (0x30).

If you are not familiar with how variables are represented in memory, I think this is a very nice tutorial. It explains what Endianness means, and how numbers are stored in a computer.

It will likely help your understanding to know that 4294914080 is 0xffff3020 when written in hexadecimal, and that:

0xff = 255
0xff = 255
0x30 = 48
0x20 = 32