Easy to understand Pointer in C

Very easy to understand pointer in C programming language

Pointers are very important not only in C programming language but any programming language. Most students don’t find it easy to understand or understand it and then forget it. Also readers might wonder why C programming language and pointers in C is mentioned in this electronics engineering blog. Well, any electronics engineer must also be good in programming languages, especially in C. Embedded systems firmware or software are usually written in C. Hence one needs to learn C and concepts such as pointers in C. Good electronics or electrical engineering may provide good foundation on C programming relating to electronics but most do not cover this aspect of life.

Let declare a integer variable called V(standing for voltage for example).

Now once this is declared a memory space is allocated for the variable V. Let’s say its address is 2000.

Now let’s create an integer pointer called p:

When a pointer is declared in C then * is used infront of the pointer variable like p or also after the data type like int*.

Once the pointer p is declared we can now store the address of variable V into the pointer. Like so,

where & is the address operator just like * is a pointer operator.

Now, we can use the pointer in two useful way.

First we can use whenever we want the address of the variable V by just using p. This is useful for example when we have bytes of data stored after the variable address. For example we can increment the pointer using p++ and access to the content after the address of the variable.

The second usefulness is that we can access the value of the variable V using pointer to the pointer p, that is, *p would give us the value of the variable V.

So, for example when we do the following:

we will get 5

That is,


It is useful because it provides a shortcut and ease of programming. But more importantly it is useful when dealing with complicated program writing which involves structures. See Very simple way to understand Structure in C.

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Leave a Reply

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

Very simple way to understand Structure in C

arrow -> in C programming language