Struct (C Programming Language) - Pointers To Struct

Pointers To Struct

Pointers can be used to refer to a struct by its address. This is particularly useful for passing structs to a function by reference. The pointer can be dereferenced just like any other pointer in C — using the * operator. There is also a -> operator in C which dereferences the pointer to struct (left operand) and then accesses the value of a member of the struct (right operand).

struct point { int x; int y; } my_point; struct point *p = &my_point; /* To declare p as a pointer of type struct point */ (*p).x = 8; /* To access the first member of the struct */ p->x = 8; /* Another way to access the first member of the struct */

Read more about this topic:  Struct (C Programming Language)