[大二上][复习]C语言中的结构体

对待技术 是什么 为什么 怎么用 这样进行讲解

结构体是一个数据类型

为什么需要结构体?

                为了表示一些复杂的事物, 而普通的基本类型无法满足实际要求

什么叫结构体?

                把一些基本数据类型组合在一起形成的一个新的复合数据类型, 这个叫做结构体                 

如何定义结构体? 

#include <stdio.h>

//第一种定义结构体
struct Student
{
	int age;
	float score;
	char sex;
}

//第二种方式定义结构体
struct Student2
{
	int age;
	float score;
	char sex;
} st2;

//第三种方式
strct
{
	int age;
	float score;
	char sex;
} st3;

int main()
{
	
}


 如何取出结构体变量中的每一个成员:

                1.结构体变量名.成员名

                2.指针变量名->成员名(这种更常用)

pst->age 在计算机内部会被转化成  (*pst).age

拓展:

        float和double 都不能准确存储

猜你喜欢

转载自blog.csdn.net/IDApprentice/article/details/126747318
今日推荐