Pointer with Structure in C
A pointer to a structure stores the address of a structure variable. It allows you to access and modify structure members through the pointer using the arrow operator (->).
Syntax
Arrow Operator (->)
When accessing members through a pointer, use -> instead of .:
Example: Pointer to Structure
Modifying Members via Pointer
Dot (.) vs Arrow (->)
| Situation | Operator | Example |
|---|---|---|
| Direct structure variable | . | s1.roll |
| Pointer to structure | -> | ptr->roll |