- to avoid creating different variables for each entity and their respective variables for each and every attribute, we can use structures.
- Structure is a group of variables of different data types represented by a single name.
- Structures are the basic foundation for objects and classes in C
- Serialization of data
- Passing multiple arguments in and out of functions through a single argument
- Data structures such as linked lists, binary trees, and more
struct point {
int x;
int y;
}
- ’ . ’ is the member accessing operator
/* draws a point at 10, 5 */
int x = 10;
int y = 5;
draw(x, y);
- Using structs, we can pass a point argument:
/* draws a point at 10, 5 */
struct point p;
p.x = 10;
p.y = 5;
draw(p);
Declaring structure variable