How does one use arrow pointers in C language?

In the C programming language, the arrow operator (->) is used to access the members of a structure or union. It provides a simplified syntax for accessing members of a structure or union through a pointer.

Imagine there is a struct defined as follows:

struct Student {
    char name[20];
    int age;
    int score;
};

Next, define a structure variable and access its members using arrow pointers.

struct Student student1;
struct Student *ptr;

ptr = &student1;  // 将结构体变量的地址赋值给指针

// 使用箭头指针访问结构体成员
ptr->age = 18;
ptr->score = 90;
strcpy(ptr->name, "John");

In the example above, the arrow pointer ptr is used to access the members of the struct student1. The syntax for using the arrow pointer is: pointer variable -> member name.

bannerAds