一个结构体小程序怎样运行的问题...

来源:百度知道 编辑:UC知道 时间:2024/05/19 09:22:25
#include <stdio.h>
void main()
{
struct st
{
int n;
struct st *next;
};
static struct st a[3]={5,&a[1],7,&a[2],9,'\0'},*p;
p=&a[0];
printf("%d",++p->n);
printf("%d",p->n++);
}

运行出来是6 5
可是是怎么考虑,弄出来的哪??
尤其A[0]也不知道啊,struct st *next啥意思?还有个'\0'......
struct st *next;
};
static struct st a[3]={5,&a[1],7,&a[2],9,'\0'},*p;
这两句还是不懂.
为什么A[0]就是指向5??

a[0]的值虽然不知道,但地址却是固定的.所以p=&a[0]你应该明白吧.那么p->n实际上就是a[0]->n,
a[0]->n的是5.
++p->n相当于++(p->n)所以值为6;
p->n++相当于(p->n)++值为5;
struct st *next定义了next为struct st 指针类型.
'\0'相当于NULL.

楼上正解。

struct st *next;
};
static struct st a[3]={5,&a[1],7,&a[2],9,'\0'},*p;
a是个数组,它有3个元素,其中每个元素指向一个结构体st,p是一个指针,它将指向st类型的元素。
a[0]在就是指向数组的首元素,这没什么好解释的,而5就是该数组的首元素。