⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex1.c

📁 零基础单片机C语言设计全套教程
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -