C language single linked list, why does the value change after reference?

  printf("data = %d\n",head->next->data);
  printf("data = %d\n",head->data);
  printf("data = %d\n",head->next->data);
There is nothing in the middle of the continuous printf, on the

main function, but the printed value has changed.

clipboard.png

C
Mar.22,2021

feels like it's only one step away from segment fault.

head- > next is really a valid pointer? Have you already been passed by free? Or not initialized? No one knows what the wild pointer will bring. printf is not without side effects, it opens up a buffer concatenation string. head- > next probably refers to where it went.


put the complete program up, the existing program is completely unable to locate the cause of the problem.

Menu