问一个关于链表的问题
程序代码:
#include <stdio.h> #include <stdlib.h> typedef struct TEST { int x; int y; TEST *nextNode; }test; void stepIn(TEST *head,int dx,int dy) { TEST *front = (TEST *)malloc(sizeof(TEST)); front->x = head->x + dx * 2; front->y = head->y + dy * 1; front->nextNode = head; head = front; } int main(void) { TEST *p1 = (TEST *)malloc(sizeof(TEST)); int dx = 1,dy = 0; p1->x = 1; p1->y = 2; p1->nextNode = NULL; stepIn(p1,dx,dy); printf("%d %d\n",p1->x,p1->y); return 0; }
输出结果是1 2
我预想中的结果是3 2
请教下原因