当前位置:网站首页>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
边栏推荐
- The short ticket hypothesis: finding sparse, trainable neural networks
- 淘宝短视频避坑指南系列之一--彻底了解淘宝短视频
- Postman interface test tool
- Some views on the current CIM (bim+gis) industry
- LeetCode 321. 拼接最大數***
- Detailed explanation of MySQL windowing function
- Canvas fire burning H5 animation JS special effects
- JS special effect of canvas divergent particle H5 animation
- 掌握高性能计算前,我们先了解一下它的历史
- canvas发散的粒子h5动画js特效
猜你喜欢

Classic topics of leetcode tree (I)

Red vertical left side menu navigation code

Chunk extend: hit training lab13

js手机端复制文本到剪切板代码

well! One new star, please look over | elder martial brother and elder martial sister say

Flutter在数字生活的发展与天翼云盘落地实践

掌握高性能计算前,我们先了解一下它的历史

The latest good article | interpretable confrontation defense based on causal inference

搭建在线帮助中心,轻松帮助客户解决问题

Why 0.1+0.2=0.3000000000000004
随机推荐
Talk about those things about telecommuting, participate in the essay solicitation, receive the contribution fee and win the grand prize!
堆利用之chunk extend: HITCON tranining lab13
YML file configuration parameter definition dictionary and list
图像搜索是什么
The development of flutter in digital life and the landing practice of Tianyi cloud disk
Abbexa 8-OHdG CLIA 试剂盒解决方案
There is an urgent need to enrich the smart home product line. Can fluorite be crowded on the sweeping robot track?
Library for adding progress bar during training --tqdm
Unity stepping on the pit record: if you inherit monobehavior, the constructor of the class may be called multiple times by unity. Do not initialize the constructor
CDGA|工业企业进行数据治理的六个关键点
yml文件配置参数定义字典和列表
Abbexa 1,3-二棕榈素 CLIA 试剂盒解决方案
小程序积分商城如何实现营销目的
IP总结(TCP/IP卷1和卷2)
Chunk extend: hit training lab13
解决 vs2022在调试程序时缓慢加载一堆符号的问题
Wireshark learning notes (I) common function cases and skills
LeetCode 255. Verifying preorder traversal sequence binary search tree*
Detailed explanation of MySQL windowing function
Memory pool principle I (based on the whole block)