Visualization of Pointer Variable in C

In this class, we will try to have Visualization of Pointer Variable in C.

Visualization of Pointer Variable in C

We have already discussed the concepts of pointer variables and address operators in our previous classes.

Visualization of Pointer Variable

To have better visualization, we will use the lines of code in the image below.

Visualization of Pointer Variable in C Example
Visualization of Pointer Variable in C Example

In the above image, we have four lines of code. Let’s visualize the concept of pointer variable line by line.

The compiler will create a block of memory bytes for the first line of code, as shown in the image below.

Visualization of Pointer Variable in C First Line
Visualization of Pointer Variable in C First Line

The number of memory bytes is maybe two or four bytes based on the compiler implementation.

In the second line of code, value ten will get assigned to the memory, as shown in the image below.

Visualization of Pointer Variable in C Second Line
Second Line

In the third line of code, the pointer variable p will be created, as shown in the image below.

Visualization of Pointer Variable in C Third Line
Third Line

The pointer variable has been created, but the value was not yet been assigned.

In the fourth line of code, the address of a is getting assigned to the pointer variable.

Now, the pointer variable p points towards variable a, as shown in the image below.

Visualization of Pointer Variable in C Fourth Line
Fourth Line