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);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值