#include <stdio.h>
#include <stdlib.h>
struct Node{
int data;
struct Node* link;
};
struct Node* A;
int main(){
struct Node* temp = (struct Node*)malloc(sizeof(Node));
temp->data = 2;
temp->link = NULL;
A = temp; // in this line i have doubt
return 0;
}
- 我们将 temp 的地址复制给了 A,因此 A 将指向同一地址。(即它们是相同的标识符/变量)
- 我们将 temp 的元素复制并赋值给了 A 的元素。(即它们是分开的标识符/变量)。通常在结构中使用这种方法。
temp
分配任何内存。而且temp->data = NULL
应该改为temp->link = NULL
。 - Barmar