// Pantea Aria // Returning a pointer to a struct // Dynamic memory allocation using malloc // dereferencing using -> // Freeing memory using free #include #include #include #define MAX_LEN 100 struct student { char name[MAX_LEN]; int id; }; // Function prototypes struct student *create_student(char *name, int id); void print_student(struct student s); int main(void) { // 1. Create a student id =12345 name = "Pantea Aria" struct student *new_student = create_student("Pantea Aria", 12345); // 2. Print student details print_student(*new_student); // 3. Free allocated memory free(new_student); return 0; } // Function to create a student and return pointer - ToDo struct student *create_student(char *name, int id) { // allocate memory for the student struct student *new = malloc(sizeof(struct student)); // check if malloc worked correctly if (new == NULL) { printf("malloc ERROR\n"); return NULL; } // assign name and id to the new struct strcpy(new->name, name); new->id = id; // return the new student return new; } // Function to print student details - ToDo void print_student(struct student s) { printf("Name: %s\n", s.name); printf("ID: %d\n", s.id); }