请C高手帮我分析这个链表的程序,我被指针绕混了,谢谢!

来源:百度知道 编辑:UC知道 时间:2024/09/23 11:21:54
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct node {
char name[20];
int num;
struct node *next;
}*head,*p;
main()
{p=(struct node*) malloc(sizeof(struct node));
head=(struct node*)malloc(sizeof(struct node));
head->next=p;/*这一行指向哪个,什么意思*/
printf("input the num\n");
scanf("%d",&p->num);/*为什么写成&p->num,p->num不是指针吗?*/
printf("input the name\n");
scanf("%s",&p->name);
printf("%s %d\n",p->name,p->num);
printf("%p %p\n",head->name,head->num); /*这输出的是谁的地址,指向谁*/
getch();
return 0;
}
谢谢!
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct node {
char name[20];
int num;
struct node *next;
}*head,*p;
main()
{p=(struct node*) malloc(sizeof(struct node));
head=(struct node*

head->next=p; /*这和行删去,运行结果一样,为什么啦,删去了有什么不同?*/
没有什么不同~如果你是写多个结点的~就有用~这好比A-B-C一路下去
你上面只有一个结点~所以有没有无所谓
为什么写成&p->num,p->num不是指针吗?*/
p才是指针~p指想NUM也就是num是指针吗
朋友你和我刚学的时候一样~一但学得久了你就决得链表很简单
指针也是好简单的~~