When you work with large structures containing arrays or many members, copying them during function calls consumes time and stack memory. A Structure Pointer allows you to refer to the original data directly via its memory address.
To declare a pointer to a structure, use the struct keyword followed by the tag name and an asterisk (*).
In C, you cannot use the dot operator (.) directly with a pointer. While you could write (*ptr).age, it is clunky. Instead, C provides the **Arrow Operator** (->) as a shorthand for accessing members via a pointer.
By passing a pointer to a function, any changes made to the structure members inside that function will permanently modify the original structure.
Structure pointers are essential when you don't know how many structures you need until the program is running. You can use malloc() to allocate space for a struct on the **Heap**.
| Feature | Structure Variable | Structure Pointer |
|---|---|---|
| Operator | Dot operator (.) |
Arrow operator (->) |
| Memory Use | Stores actual data values | Stores a 4 or 8-byte address |
| Efficiency | Slow for large structures | Highly efficient |
-> for the level that is a pointer. For example, if ptr is a pointer to a struct that contains a normal struct dob, use: ptr->dob.year.