arrow -> in C programming language

what is arrow -> in C programming language

In this C programming article, you will learn what is arrow -> in C programming language. If you have studied in good electronics or electrical engineering college then you might know what is arrow -> in C programming language. Most of us don’t because this arrow sign appears in more advanced courses in C that involves structures. It may be taught in bachelor degree in engineering or also in software engineering courses but not so much in electronics engineering courses.

So what is arrow -> in C programming language?

Arrow -> in C programming language is just access operator to structure elements when using pointer just like the dot access operator to structure elements when using structure variable. Just look at the example code below and you will understand it easily.

Remember the student structure used in the earlier blog post Very simple way to understand Structure in C. It is as follows.

Let’s use it in main.c program, by creating an instance x of the structure struc student.

To assign value to the structure elements such as age we use the dot operator as follows.

Let also create now a pointer p to the structure student which is done just like with any data types.

And let assign the address of the structure student variable x,

Now lets write that in the above main code.

Now the question is how to access/retrieve the structure student variable value such as age(or name) using the pointer?

The solution is to use the arrow operator(->) like so,


This is just like x.age. But since we want to use the pointer p we have to use the arrow operator. If this is printed then we get 20 just like x.age.

If you are confused about pointer see Easy to understand Pointer 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 *

Easy to understand Pointer in C

Reading and Writing data to USART in MPLAB harmony

Reading and Writing data to USART in MPLAB harmony