[编程] C语言的结构体
结构体
struct 结构体名{} 变量名;
结构体变量:
struct person{
char *name;
int age;
float score;
} student;
成员的获取和赋值
//Members of the acquisition and assignment
student.name="taoshihan";
student.age=30;
student.score=100;
printf("name=%s \n",student.name);
C语言结构体数组
struct stu{
char *name;
int age;
float score;
} classes[5];
遍历结构体数组
struct people{
char *name;
int age;
float score;
} d[]={
{"taoshihan",20,100},
{"lisi",30,90}
};
int len=sizeof(d)/sizeof(d[0]);
printf("d length=%d \n",len);
for(int i=0;i<len;i++){
printf("loop...%s,%d,%.1f \n",d[i].name,d[i].age,d[i].score);
}
C语言结构体和指针
struct 结构体名 *变量名;
struct person1{
char *name;
int age;
float score;
} a={"taoshihan",20,100},*b=&a;
struct person1 *c=&a;
获取结构体成员
printf("b.name=%s \n",(*b).name);
printf("c.name=%s \n",c->name);
完整代码:
#include <stdio.h>
int main(){ printf("hello world");
//Structure variables
struct person{
char *name;
int age;
float score;
} student; //Members of the acquisition and assignment
student.name="taoshihan";
student.age=;
student.score=;
printf("name=%s \n",student.name); //c struct array
struct stu{
char *name;
int age;
float score;
} classes[]; struct stu1{
char *name;
int age;
float score;
} classes1[]={
{"taoshihan",,100.00},
{"lisi",,}
}; struct stu2{
char *name;
int age;
float score;
} classes3[]={
{"taoshihan",,}
};
printf("%s \n",classes1[].name); //Traverse the array of structures
struct people{
"chaper5.c" 71L, 1199C , Top
//Traverse the array of structures
struct people{
char *name;
int age;
float score;
} d[]={
{"taoshihan",,},
{"lisi",,}
};
int len=sizeof(d)/sizeof(d[]);
printf("d length=%d \n",len);
for(int i=;i<len;i++){
printf("loop...%s,%d,%.1f \n",d[i].name,d[i].age,d[i].score);
} //C language structure and pointer
struct person1{
char *name;
int age;
float score;
} a={"taoshihan",,},*b=&a;
struct person1 *c=&a;
//Get the structure member printf("b.name=%s \n",(*b).name);
printf("c.name=%s \n",c->name);
}
[编程] C语言的结构体的更多相关文章
- C语言中结构体对齐问题
C语言中结构体对齐问题 收藏 关于C语言中的结构体对齐问题 1,比如: struct{short a1;short a2;short a3;}A;struct{long a1;short a2;}B; ...
- Go语言中结构体的使用-第2部分OOP
1 概述 结构体的基本语法请参见:Go语言中结构体的使用-第1部分结构体.结构体除了是一个复合数据之外,还用来做面向对象编程.Go 语言使用结构体和结构体成员来描述真实世界的实体和实体对应的各种属性. ...
- Go语言中结构体的使用-第1部分结构体
1 概述 结构体是由成员构成的复合类型.Go 语言使用结构体和结构体成员来描述真实世界的实体和实体对应的各种属性.结构体成员,也可称之为成员变量,字段,属性.属性要满足唯一性.结构体的概念在软件工程上 ...
- Go语言 6 结构体、方法和接口
文章由作者马志国在博客园的原创,若转载请于明显处标记出处:http://www.cnblogs.com/mazg/ Go学习群:415660935 结构体(struct)是由一系列具有相同类型或不同类 ...
- C语言利用结构体数组实现学生成绩管理系统
这篇文章主要为大家详细介绍了C语言利用结构体数组实现学生成绩管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 要求: 某班有最多不超过30人(具体人数由键盘输入) ...
- C语言中结构体赋值问题的讨论
今天帮师姐调一个程序的BUG,师姐的程序中有个结构体直接赋值的语句,在我印象中结构体好像是不能直接赋值的,正如数组不能直接赋值那样,我怀疑这个地方有问题,但最后证明并不是这个问题.那么就总结一下C语言 ...
- C语言的结构体和C++结构体的区别
关于C++中声明结构体中需要使用构造器创建实例对象的语法: <C++的结构体构造方法的基本概念:结构体的构造方法需要和结构体的名字相同,并且无返回值,也不要void关键字,这样的方法就是构造器的 ...
- 01.C语言关于结构体的学习笔记
我对于学习的C语言的结构体做一个小的学习总结,总结如下: 结构体:structure 结构体是一种用户自己建立的数据类型,由不同类型数据组成的组合型的数据结构.在其他高级语言中称为记录(record) ...
- 逆向知识第十四讲,(C语言完结)结构体在汇编中的表现形式
逆向知识第十四讲,(C语言完结)结构体在汇编中的表现形式 一丶了解什么是结构体,以及计算结构体成员的对其值以及总大小(类也是这样算) 结构体的特性 1.结构体(struct)是由一系列具有相同类型或不 ...
随机推荐
- gitlab中修改项目名称客户端修改方法
如果gitlab项目名称已经修改,对于本地已经克隆下来的仓库,可以使用如下命令进行修改: git remote set-url origin 新的项目路径
- 利用C# CefSharp Python采集某网站简历并自动发送邀请短信
以往爬虫没怎么研究过,最近有个需求,要从某网站采集敏感信息,稍稍考虑了一下,决定利用C# Winform和Python一起来解决这个事件. 整个解决方案不复杂:C#编写WinForm窗体,进行数据分析 ...
- 调用jdbc已经写成的方法----jdbc工具类抽取方式二
先创建db.properties driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/web08?useUnicode=true& ...
- python中type、class、object的区别
type 一. type可以用来返回一个对象的类型 例如: 二. 由于Python中一切皆对象,也就是说Python中的任何变量类型都是可以被修改的,这也是Python等动态编程语言的特点.type的 ...
- spring属性配置执行过程,单列和原型区别
Spring配置中,采用属性注入时,当创建IOC容器时,也直接创建对象,并且执行相对应的setter方法 Student.java package com.scope; public class St ...
- RDD转换成为DataFrame
方式一: 通过case class创建DataFrames(反射) TestDataFrame1.scala package com.bky // 隐式类的导入 // 定义case class,相当于 ...
- 2018-2019 20165226 Exp7 网络欺诈防范
2018-2019 20165226 Exp7 网络欺诈防范 目录 一.实验内容说明及基础问题回答 二.实验过程 1.简单应用SET工具建立冒名网站 2.ettercap DNS spoof 3.结合 ...
- Redis学习笔记(6)——SpringDataRedis入门
一.SpringDataRedis简介 Spring-data-redis是spring大家族的一部分,提供了在srping应用中通过简单的配置访问redis服务,对reids底层开发包(Jedis, ...
- 使用二叉搜索树实现一个简单的Map
之前看了刘新宇大大的<算法新解>有了点收获,闲来无事,便写了一个二叉搜索树实现的Map类. java的Map接口有很多不想要的方法,自己定义了一个 public interface IMa ...
- (四)Audio子系统之AudioRecord.read
在上一篇文章<(三)Audio子系统之AudioRecord.startRecording>中已经介绍了AudioRecord如何开始录制音频,接下来,继续分析AudioRecord方 ...