int a = 33; int *p=&a; char a; char b=2; xxx var; char *name="Tanya"; char *ptr = &name; char a[] = "asd"; char *b = "asd"; char c = 'a'; int first; int second = 2; char u; char chr = 'a'; int seccopy = second; char *p = &chr; int *secptr = &second; char *chrptr = &chr; char *str = "UV"; int array[3]; char string_literal[] = "string-literal";

This is a C language pointers tutorial. It's purpose is to show how primitive types like 'int', 'char' and pointers are laid out in computer memory.

It supports a subset of the C language and in some cases deviates from the language. Your program is limited to declarations only. No real code allowed. Arithmetic operations are not suppored. Type checks are very limited - in many cases you can assign pointers of different types without type coercion.

In the "Source" window you can enter your C language program. It will be compiled into memory layout which is displayed above in the "Real thing" stripe.

The "Real thing" is a simulation of a computer with 256 bytes of memory, 4 byte-wide integer type, 1 byte char type and 2 byte poitner type. All the bytes are displayed in the "Real thing" stripe above. You can scroll it by dragging left and right with a mouse.

Next page

Memory is shown as a stripe of memory cells. Under each cell there is the cell address in hexadecimal. Inside of each cell it's contents is shown.

Unallocated memory cells are shown in GRAY.

Allocated but uninitialized memory cells are shown in RED.

Allocated and uninitialized memory cells are shown in GREEN.

Whatever you entered into "Source" block is compiled and displayed in the "Real thing" block.

As you edit your source code the memory stripe is updated automatically.

Next page

Any errors in your programs are shown in red in the ERROR area.

Next page

Pointers are shown as blue arrows from pointer to the pointee.

Here you can see a pointer variable "name" pointing to unnamed block of memory which contains characters "Tanya", and a char pointer which points to name itself (here we differ from the real C language - it will be double pointer in the language).

Next page

Ever wondered what is the difference between char [] and char *?

Next page

More features are shown here. Feel free to explore on your own.

Memory and pointers demonstration

Real thing

Memory size: 256 bytes, Endianness: little, Integer size: 4, Char size: 1, Pointer size: 2, Padding: 0

Abstract thing

Source

 

1

Tutorial

(Source on Github)