/* 第一种方式:定义一个结构体*//* 这种方式应用更多*/structcomm
{
int heard;
int lenth;
int addmast;
int addslav;
int ctr;
int end;
int crc;
}
/* 第二种方式:定义一个结构体*//* 定义结构体同时定义结构体变量*/structcomm
{
int heard;
int lenth;
int addmast;
int addslav;
int ctr;
int end;
int crc;
}commucation;
/* 第二种方式:定义一个结构体*//* 定义结构体同时定义结构体变量,但是不定义结构体名称*/struct
{
int heard;
int lenth;
int addmast;
int addslav;
int ctr;
intend;
int crc;
}commucation;
5:结构体程序范例
/*普通结构体定义,初始化,赋值*/# include<stdio.h>struct comm
{
int heard;
int add;
int ctr;
int crc;
};
int main()
{
struct comm test;//结构体初始化
test.heard = 1;//结构体赋值
test.add = 2;
test.ctr = 3;
test.crc = 4;
printf("%d,%d,%d,%d\n",test.heard,test.add,test.ctr, test.crc);
return0;
}
/*普通结构体定义,初始化,赋值*/
# include<stdio.h>
structcomm
{
int heard;
int add;
int ctr;
int crc;
};
int main()
{
structcomm test ;//定义结构体变量 structcomm * p = &test;//定义指向结构体变量的指针变量
p ->heard = 1;//结构体变量的赋值
p -> add = 2;
p -> ctr = 3;
p -> crc = 4;
printf("%d,%d,%d,%d\n",p -> heard,p -> add, p -> ctr, p -> crc);
return0;
}