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);
}
相关推荐
逐闲29 分钟前
LeetCode热题100【第一天】
算法·leetcode
爱吃涮毛肚的肥肥(暂时吃不了版)30 分钟前
剑指offer——模拟:顺时针打印矩阵
算法·leetcode·矩阵
chao_78931 分钟前
动态规划题解——乘积最大子数组【LeetCode】
python·算法·leetcode·动态规划
今天背单词了吗9801 小时前
算法学习笔记:16.哈希算法 ——从原理到实战,涵盖 LeetCode 与考研 408 例题
笔记·学习·算法
前端拿破轮2 小时前
字符串消消乐你会吗?😋😋😋
算法·leetcode·面试
koooo~2 小时前
JavaScript 与 C语言基础知识差别
c语言·开发语言·javascript
EndingCoder2 小时前
图算法在前端的复杂交互
前端·算法·图算法
mit6.8242 小时前
[Nagios Core] 通知系统 | 事件代理 | NEB模块,事件,回调
c语言·开发语言
mit6.8242 小时前
[Nagios Core] 事件调度 | 检查执行 | 插件与进程
c语言·开发语言·性能优化
kanhaoning2 小时前
将重排序大模型Qwen3-Reranker-8B的知识蒸馏到小模型BGE-reranker-v2-m3上
算法