Hi, everyone! The following code creates a linked list, and then free the memory for the list. I'm just a starter on C. Is the code correct? Thanks in advance!
Code:#include <stdlib.h> #define MAX 3 int main (void) { int i; struct list { char c; struct list *next; }; struct list *start, *list_ptr; start = malloc(sizeof(struct list)); list_ptr = start; for (i = 0; i < MAX; i++) { list_ptr->next = malloc(sizeof(struct list)); list_ptr = list_ptr->next; } list_ptr->next = NULL; while (start) { list_ptr = start; start = list_ptr->next; free(list_ptr); } return 0; }