C语言结构体

c 复制代码
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
//struct Student_s {
//	int num;
//	char name[20];
//	char gender;
//	int age;
//	float Chinese;
//	float Math;
//	float English;
//	char addr[30];
//};
//最后的分号一定要写!!!!!!

//typedef struct Student_s Student_t;
//typedef struct Student_s* pStudent_t;

//下面的结构体定义方式更常用!
typedef struct{
	int num;
	char name[20];
	char gender;
	int age;
	float Chinese;
	float Math;
	float English;
	char addr[30];
} Student_t, *pStudent_t;

int main() {
    //结构体赋值,所有的数据成员都拷贝了一份
	//struct Student_s stu1 = {1001, "Wuyifan", 'M', 30, 75, 70, 100, "Canada"};
	//struct Student_s stu2;
	//stu2 = stu1;
    
    //结构体数组
	Student_t stu[3] = {
		1001,"Wuyifan",'M',30,75,70,100,"Canada",
		1003,"Zhaowei",'F',45,80,85,70,"Anhui",
		1005,"Sunhonglei",'M',50,90,90,60,"Heilongjiang"
	};
	
    //从标准输入读取数据,给数据成员赋值
	//for (int i = 0; i < 3; ++i) {
    //  %c前面加上空格,表示忽略前置空白字符
	//	scanf("%d%s %c%d%f%f%f%s",
	//		&stu[i].num, stu[i].name, &stu[i].gender, &stu[i].age,
	//		&stu[i].Chinese, &stu[i].Math, &stu[i].English, stu[i].addr);
	//}
	
    //结构体指针
	pStudent_t p = stu;
	printf("(*p).num = %d\n", (*p).num);//*比. 优先级更低,所以需要加括号
	// -> 和 (*).等价
	printf("p->num = %d\n", p->num);//和上一个是等价的
	int num = p->num++;
	printf("num = %d, p->num = %d\n", num, p->num);
	num = p++->num;
	printf("num = %d, p->num = %d\n", num, p->num);
	num = ++p->num;
	printf("num = %d, p->num = %d\n", num, p->num);
}
相关推荐
七灵微17 分钟前
数据结构实验习题
数据结构
三维重建-光栅投影1 小时前
VS中将cuda项目编译为DLL并调用
算法
课堂剪切板4 小时前
ch03 部分题目思路
算法
山登绝顶我为峰 3(^v^)35 小时前
如何录制带备注的演示文稿(LaTex Beamer + Pympress)
c++·线性代数·算法·计算机·密码学·音视频·latex
Two_brushes.6 小时前
【算法】宽度优先遍历BFS
算法·leetcode·哈希算法·宽度优先
森焱森8 小时前
水下航行器外形分类详解
c语言·单片机·算法·架构·无人机
QuantumStack10 小时前
【C++ 真题】P1104 生日
开发语言·c++·算法
写个博客10 小时前
暑假算法日记第一天
算法
绿皮的猪猪侠10 小时前
算法笔记上机训练实战指南刷题
笔记·算法·pta·上机·浙大
hie9889411 小时前
MATLAB锂离子电池伪二维(P2D)模型实现
人工智能·算法·matlab