The pointer and structural structure can include a pointer, of course, a pointer to the other instance of the same structure:, for example: struct node {struct node * next_ptr; int value;} Carefully think about it, now we find that if we can create NODE, The data we can save in memory can reach infinity. So we need a such program that when the user says "I want a new node", the program can create it. Of course, it cannot be used in light. Therefore, we can create the following program: #include struct node {struct node * next_ptr; int value;}; struct node * first_ptr; void add_list (int item) {struct node * new_item_ptr = malloc (sizeof (struct node )); (* New_item_ptr) .Value = item; (* new_item_ptr) .next_ptr = first_ptr; first_ptr = new_item_ptr;} int main () {INT J = 0; int i = j; struct node * current_ptr; scanf ("% D ", & I); for (; j <= i; j ) add_list (j); current_ptr = first_ptr; while (current_ptr! = null) {printf ("% d / n ", (* current_ptr) .value); First_PTR = (* first_ptr) .next_ptr; free (current_ptr); current_ptr = null; current_ptr = first_ptr;} current_ptr = first_ptr; return 0;}
Excerpted from: Spicy Sister Community - C / C Forum