Chapter
Declaration & Initialization
From ComputerScienceOne by Dr Chris Bourke
Concepts
- How can one structure be composed of another structure?
"typedef struct {\n\nint id;\n\nchar *firstName;\n\nchar *lastName;\n\ndouble gpa;\n\nDate dateOfBirth;\n\n} Student;\n\nCode Sample 23.1.: A Student structure declaration\n\ntypedef struct {\n\nint y
- How are structure instances declared and initialized?
"Once we have defined a structure (and included the header file it has been defined in), we can create instances using the usual syntax.\n\nStudent s;\n\nStudent t;\n\nThese static declarations will a
- How can structures be dynamically allocated?
"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 struct