您的位置:首页 > 其它

p7 struct and union

2016-01-04 11:52 176 查看
struct StudentRec //①声明结构体类型StudentRec
{
char StuNum[20]; //②定义结构体的成员变量
char StuName[20]; //②                  1.Dot “.” is called the member selection operator.
                                  2. After the struct type declaration, the various members can

                                  be used in your program only when they are preceded by a struct variable name and a dot.
int Score1; //②
int Score2; //②
int Admit; //②
} ;

//用结构体类型定义变量stu1和stu2
struct StudentRec stu1, stu2;

//访问结构体变量stu1中的成员
strcpy(stu1.StuNum, "0001");
strcpy(stu1.StuName, "Zhangsan");
stu1.Score1 = 90;
stu1.Score2 = 100;
stu1.Admit = 1;
printf( "%s %s %d %d %d\n",
stu1.StuNum, stu1.StuName,
stu1.Score1, stu1.Score2, stu1.Admit );

struct studentRec* pStu;

strcpy( pStu->num, “1000” );
strcpy( pStu->num, “Linda”;
pStu->Sccore1 =89;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: