结构体指针和数组理解
(1)第一个
1 # include<iostream> 2 using namespace std; 3 struct student 4 { 5 int num; 6 char name[12]; 7 char sex; 8 int age; 9 }//stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 10 *st; 11 struct student stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 12 int main() 13 { 14 //struct student *st; 15 16 for(st = stu; st < stu+3; st++) 17 { 18 cout<<(*st).num<<" "<<(*st).name<<" "<<(*st).sex<<" "<<(*st).age<<endl; 19 20 } 21 cout<<"------------------------------------------------"<<endl; 22 for(st = stu; st < stu+3; st++) 23 { 24 cout<<st->num<<" "<<st->name<<" "<<st->sex<<" "<<st->age<<endl; 25 } 26 27 }
View Code
(2)第二个
1 # include<iostream> 2 using namespace std; 3 struct student 4 { 5 int num; 6 char name[12]; 7 char sex; 8 int age; 9 }//stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 10 ; 11 struct student stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 12 int main() 13 { 14 struct student *st; 15 16 for(st = stu; st < stu+3; st++) 17 { 18 cout<<(*st).num<<" "<<(*st).name<<" "<<(*st).sex<<" "<<(*st).age<<endl; 19 20 } 21 cout<<"------------------------------------------------"<<endl; 22 for(st = stu; st < stu+3; st++) 23 { 24 cout<<st->num<<" "<<st->name<<" "<<st->sex<<" "<<st->age<<endl; 25 } 26 27 }
View Code
(3)第三个
1 # include<iostream> 2 using namespace std; 3 struct student 4 { 5 int num; 6 char name[12]; 7 char sex; 8 int age; 9 }stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 10 11 //struct student stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 12 int main() 13 { 14 struct student *st; 15 16 for(st = stu; st < stu+3; st++) 17 { 18 cout<<(*st).num<<" "<<(*st).name<<" "<<(*st).sex<<" "<<(*st).age<<endl; 19 20 } 21 cout<<"------------------------------------------------"<<endl; 22 for(st = stu; st < stu+3; st++) 23 { 24 cout<<st->num<<" "<<st->name<<" "<<st->sex<<" "<<st->age<<endl; 25 } 26 27 }
View Code
(4)第四个(注意看typedef)
1 # include<iostream> 2 using namespace std; 3 typedef struct student 4 { 5 int num; 6 char name[12]; 7 char sex; 8 int age; 9 }//stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 10 stt; 11 stt stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 12 int main() 13 { 14 stt *st; 15 16 for(st = stu; st < stu+3; st++) 17 { 18 cout<<(*st).num<<" "<<(*st).name<<" "<<(*st).sex<<" "<<(*st).age<<endl; 19 20 } 21 cout<<"------------------------------------------------"<<endl; 22 for(st = stu; st < stu+3; st++) 23 { 24 cout<<st->num<<" "<<st->name<<" "<<st->sex<<" "<<st->age<<endl; 25 } 26 27 }
View Code
转载于:https://www.cnblogs.com/sxmcACM/p/3463609.html
结构体指针和数组理解相关推荐
- go语言json字符串解析为结构体数组,结构体指针的数组
废话不多说直接上效果图 完整代码如下 package main import ("encoding/json""fmt" ) // 结构体定义 type rob ...
- C语言—用结构体指针给数组赋值(结构体指针指向字符串,给字符串赋值)
数组定义: char acBuf[sizeof(TRANS_HEAD_S) + sizeof(USER_HEAD_S) + 4] = {0}; 结构体定义: typedef struct {int i ...
- c语言中指针数组赋值字符串,C语言—用结构体指针给数组赋值(结构体指针指向字符串,给字符串赋值)...
数组定义: char acBuf[sizeof(TRANS_HEAD_S) + sizeof(USER_HEAD_S) + 4] = {0}; 结构体定义: typedef struct { int ...
- 【C语言】深度探索offsetof,解析结构体的成员数组和指针
目录 一.offsetof的功能 二.自定义offsetof 三.探索结构体 3.1结构体中的成员 3.2结构体指针和数组 该篇博客主要讲了自定义offsetof是如何实现的,为什么要这样写,以此沿生 ...
- C语言结构体和结构体指针的简单用法
C语言结构体和结构体指针的简单用法 这里总结一下自己的学习笔记,关于C语言当中的结构体指针的用法,以及结构体简单使用. 简单介绍一下今天出场的嘉宾–>结构体和结构体指针 什么是结构体: 1,定义 ...
- go 打印结构体对象,结构体指针
简言 1. go语言提供了简洁的打印功能,比如%d, %v, %+v等等,具体可以参考笔者的这篇博客 https://blog.csdn.net/yzf279533105/article/detail ...
- 指向结构体的指针和指向结构体指针的指针
例如,struct T *ptr;是指向一个结构体的指针,也可以当做一个结构体数组来用. 可以把结构体当做 int 来看,int* 类型即可以指向一个整数,也可以指向数组. struct T ** p ...
- 自己实现了一个C语言例程,加深对宏、大小端、typeof宏、offsetof宏、指针变量、结构体、联合体的理解
如题所述,最近时间在复习C语言.自己实现了一个C语言例程,以加深对宏.大小端.typeof宏.offsetof宏.指针变量.结构体.联合体的理解.关于细分知识后续有空再填充- swap宏的使用: 对应 ...
- 我在微信上大学:如何正确理解指针和结构体指针?
一直觉得C语言较其他语言最伟大的地方就是C语言中的指针,有些人认为指针很简单,而有些人认为指针很难,当然这里的对简单和难并不是等价于对指针的理解程度. 为此在这里对C语言中的指针进行全面的总结,从底层 ...
最新文章
- 《人类简史》八、融合统一(下)——宗教的法则、历史的混沌
- c++map的使用_mybatis源码 | mybatis插件及动态代理的使用
- java 登录按钮响应数据库_用户登录功能的实现—从前端到后台(包括数据库)...
- 企业在管理系统方面要有主动权
- iOS开发 -------- AFNetworking使用中遇到的小问题
- LeetCode-字符串-58. 最后一个单词的长度
- SpringBoot+Vue视频干货
- 服务发现比较:Consul vs Zookeeper vs Etcd vs Eureka
- Oracle数据库之数据类型
- BDD 与DSL 入门
- python中imread导入失败_ImportError:无法导入加载图像文件所需的Python Imaging Library(PIL)...
- SQL Server 2005系列教学(9) SQL 存储过程
- 点云谱聚类实现代码_Spark跑DBSCAN算法,工业级代码长啥样?
- html中横线中间加字_干货|学术论文中的“三线表”如何绘制?
- BNU 斩(超级大水题)
- 参考文献类型标识码--中英文对照
- (数据结构)二叉树中序遍历
- 微信小程序-API的Promise化
- Excel无法打开文件xxx.xlsx,因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配
- 用python做一个简单的投票程序_如何编写一个自动投票程序