Concept
How can structures be dynamically allocated?
ComputerScienceOne / Declaration & Initialization
"To solve this, we can instead use dynamically allocated structures. To dynamically allocate a structure, we use a pointer to a structure and a call to malloc() to allocate enough space for the structure. Even though our structure is user-defined, we can still use the sizeof() macro to determine the number of bytes required by the structure. The compiler and macro are “smart” enough to look at the structure declaration and determine the size of each of its variables and add up the total number of bytes required."
Related Ideas
- How can one structure be composed of another structure?ComputerScienceOne · Declaration & Initialization
- How do you dynamically allocate and initialize a structure?ComputerScienceOne · Selection Operators
- How does malloc() allocate memory for a dynamic array?ComputerScienceOne · Dynamic Memory
- How do you use and validate a dynamically allocated array?ComputerScienceOne · Dynamic Memory
- How do you deallocate dynamically allocated arrays?ComputerScienceOne · Using Arrays with Functions