Concept

How do you dynamically allocate and initialize a structure?

ComputerScienceOne / Selection Operators

"Student *s = (Student *) malloc(sizeof(Student) * 1); The multiplication by 1 in this example is not strictly necessary, but emphasizes the fact that we are allocating space for one structure and not an array of structures. Initializing a dynamically allocated structure like this does not initialize any of its variables as there are no default values defined by C. Moreover, it does not initialize memory for any pointer member variables. For example the firstName and lastName pointers need to be manually initialized with additional malloc() calls."

Related Ideas

How do you dynamically allocate and initialize a structure? | ComputerScienceOne | Bifalgorithm | Bifalgorithm