我正在尝试使用C中的结构从链表中删除元素。没有意义的部分是我为它编写了一个函数,并且当放置在main函数中时,函数的同一主体产生不同的结果。
#include<stdio.h>
struct entry {
int value;
struct entry *next;
};
void removeEntry(struct entry *prior) {
prior = prior -> next;
}
int main(void) {
struct entry e1;
e1.value = 1;
struct entry listPointer;
listPointer.next = &e1;
struct entry e2;
e2.value = 2;
struct entry e3;
e3.value = 3;
e1.next = &e2;
e2.next = &e3;
e3.next = (struct entry *) 0;
removeEntry(listPointer.next);
printf("%i\n", listPointer.next -> value);
listPointer.next = listPointer.next -> next;
printf("%i\n", listPointer.next -> value);
return 0;
}
输出:
1
2