当前位置:网站首页>c语言---10 初识结构体
c语言---10 初识结构体
2022-06-10 17:31:00 【要努力丫!】
结构体是C语言中特别重要的知识点,结构体使得C语言有能力描述复杂类型,通过下面的例子来理解和学习。
//结构体可以让C语言创建新的类型出来
//比如创建一个学生的信息,包括名字、年龄以及分数
struct stu
{
char name[20];
int age;
double score;
};
//创建一个书的类型,包括书名、价格以及id号码
struct book
{
char name[20];//成员变量
float price;
char id[30];
};
//结构体的创建和初始化
int main()
{
struct stu s = {
"张三",20,85.5};
printf("第一次打印:%s %d %lf",s.name,s.age,s.score);//.操作符,“结构体变量.成员变量”
struct stu * ps = &s;//struct stu是结构体指针
printf("第二次打印:%s %d %lf\n", (* ps).name, (*ps).age, (*ps).score);
//当我们把一个结构体的地址交给指针的时候,它也能够打印出来相应的内容。
printf("第三次打印:%s %d %lf\n",ps->name,ps->age,ps->score);
//结构体指针->成员变量名
return 0;
}
运行结果为:
第一次打印:张三 20 85.500000第二次打印:张三 20 85.500000
第三次打印:张三 20 85.500000
边栏推荐
- 云计算搭建全部内容总结,保证可以搭建一个完整的云计算服务器,包括节点安装、实例的分配和网络的配置等内容
- Abbexa AML1 DNA 结合 ELISA 试剂盒说明书
- Cdga| six key points of data governance for industrial enterprises
- 美学心得(第二百三十七集) 罗国正
- 一文带你了解J.U.C的FutureTask、Fork/Join框架和BlockingQueue
- Some views on the current CIM (bim+gis) industry
- True thesis of information system project manager in the first half of 2022
- 苹果期待的「无密码时代」,真能实现吗?
- Protocol Gen go grpc 'is not an internal or external command, nor is it a runnable program or batch file
- QTableWidget / QTableView实用技巧
猜你喜欢

高数_第6章无穷级数__正项级数的性质

Wireshark learning notes (I) common function cases and skills

Container containing the most water

c语言---14 循环语句for

MYSQL开窗函数详解

IP summary (tcp/ip volumes 1 and 2)

Leetcode 875. 爱吃香蕉的珂珂

Canvas fire burning H5 animation JS special effects

线性移动棋

well! One new star, please look over | elder martial brother and elder martial sister say
随机推荐
用脚本添加URP的RendererData
传统企业在进行信息化升级的过程中,如何做好信息化顶层设计
Why 0.1+0.2=0.3000000000000004
Container containing the most water
安装Linux系统的MySQL,在xshell中遇见的问题
c语言---14 循环语句for
js模糊阴影跟随动画js特效插件
【技术分析】探讨大世界游戏的制作流程及技术——前期流程篇
High number_ Chapter 6 infinite series__ Properties of positive series
待办事项桌面插件,办公族的桌面好帮手
云计算搭建全部内容总结,保证可以搭建一个完整的云计算服务器,包括节点安装、实例的分配和网络的配置等内容
CUDA实现高效查找--审核未通过?
Numpy - record
Summary of all contents of cloud computing setup to ensure that a complete cloud computing server can be built, including node installation, instance allocation, network configuration, etc
PCA principal component analysis tutorial (origin analysis & drawing, without R language)
Summary of vim common commands
Swin_Transformer源码解读
Leetcode 875. 爱吃香蕉的珂珂
The latest good article | interpretable confrontation defense based on causal inference
One of the Taobao short video pit avoidance Guide Series -- thoroughly understand Taobao short video