ex1.c

来自「零基础单片机C语言设计全套教程」· C语言 代码 · 共 25 行

C
25
字号
#include <stdio.h>							//头文件
struct student								//声明结构
{ 
int 	num;									//学号
char name[20];								//姓名
char sex[2];								//性别
int 	age;									//年龄
float score;								//分数
}Bob={101,"Bob","M",22, 90.0};				//声明并初始化结构变量

void main()								//主函数
{
struct student *pstu;							//声明结构指针
pstu=&Bob;									//为结构指针赋值
										//采用第一种方式输出成员值
printf("Name=%s,Num=%d\n",Bob.name,Bob.num);
printf("Age=%d,Sex=%s,score=%f\n",Bob.age,Bob.sex,Bob.score);
										//采用第二种方式输出成员值
printf("Name=%s,Num=%d\n",(*pstu).name,(*pstu).num);
printf("Age=%d,Sex=%s,score=%f\n",(*pstu).age,(*pstu).sex,(*pstu).score);
										//采用第三种方式输出成员值
printf("Name=%s,Num=%d\n",pstu->name,pstu->num);
printf("Age=%d,Sex=%s,score=%f\n",pstu->age,pstu->sex,pstu->score);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?