Structs
Definition & Declaration
Structures are user-defined data types in C that allow grouping different types of data under a single name.
To use the structure:
Direct Initialization
Directly upon declaration:
Fewer values than structure members:
Using member names for clarity:
Compound Literals (C11 only)
They provide a way to assign values to structures in a single statement.
Structure Arrays
Declaration of an array of structures:
Initialization:
OR
Structures Containing Arrays
Structures can contain arrays as members:
This can represent a month with its number of days and a 3-character name.
Nested Structures
Allows for structures to contain other structures:
Pointers to Structures
Declaring a pointer to a struct:
Setting and accessing data:
Structures and Functions
Structures can be both arguments to functions and return types:
Structures Containing Pointers
Structures can also contain pointers:
Last updated