结构体

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语言的结构体的更多相关文章

  1. C语言中结构体对齐问题

    C语言中结构体对齐问题 收藏 关于C语言中的结构体对齐问题 1,比如: struct{short a1;short a2;short a3;}A;struct{long a1;short a2;}B; ...

  2. Go语言中结构体的使用-第2部分OOP

    1 概述 结构体的基本语法请参见:Go语言中结构体的使用-第1部分结构体.结构体除了是一个复合数据之外,还用来做面向对象编程.Go 语言使用结构体和结构体成员来描述真实世界的实体和实体对应的各种属性. ...

  3. Go语言中结构体的使用-第1部分结构体

    1 概述 结构体是由成员构成的复合类型.Go 语言使用结构体和结构体成员来描述真实世界的实体和实体对应的各种属性.结构体成员,也可称之为成员变量,字段,属性.属性要满足唯一性.结构体的概念在软件工程上 ...

  4. Go语言 6 结构体、方法和接口

    文章由作者马志国在博客园的原创,若转载请于明显处标记出处:http://www.cnblogs.com/mazg/ Go学习群:415660935 结构体(struct)是由一系列具有相同类型或不同类 ...

  5. C语言利用结构体数组实现学生成绩管理系统

    这篇文章主要为大家详细介绍了C语言利用结构体数组实现学生成绩管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 要求: 某班有最多不超过30人(具体人数由键盘输入) ...

  6. C语言中结构体赋值问题的讨论

    今天帮师姐调一个程序的BUG,师姐的程序中有个结构体直接赋值的语句,在我印象中结构体好像是不能直接赋值的,正如数组不能直接赋值那样,我怀疑这个地方有问题,但最后证明并不是这个问题.那么就总结一下C语言 ...

  7. C语言的结构体和C++结构体的区别

    关于C++中声明结构体中需要使用构造器创建实例对象的语法: <C++的结构体构造方法的基本概念:结构体的构造方法需要和结构体的名字相同,并且无返回值,也不要void关键字,这样的方法就是构造器的 ...

  8. 01.C语言关于结构体的学习笔记

    我对于学习的C语言的结构体做一个小的学习总结,总结如下: 结构体:structure 结构体是一种用户自己建立的数据类型,由不同类型数据组成的组合型的数据结构.在其他高级语言中称为记录(record) ...

  9. 逆向知识第十四讲,(C语言完结)结构体在汇编中的表现形式

    逆向知识第十四讲,(C语言完结)结构体在汇编中的表现形式 一丶了解什么是结构体,以及计算结构体成员的对其值以及总大小(类也是这样算) 结构体的特性 1.结构体(struct)是由一系列具有相同类型或不 ...

随机推荐

  1. DP刷题

    http://blog.csdn.net/a1dark/article/details/17115137

  2. ESXi到KVM之v2v迁移

    1.ESXi到KVM之v2v情况说明 (1).配置任务列表: 1)VMwareESXi虚拟平台下linux系统迁移到KVM虚拟平台.2)VMwareESXi虚拟平台下windows系统迁移到KVM虚拟 ...

  3. html实现时间输入框

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. elasticsearch-5.1.1 安装的问题

    elasticsearch 5.1 安装过程中遇到了一些问题做一些记录. 问题一:警告提示 [2016-12-20T22:37:28,543][INFO ][o.e.b.BootstrapCheck ...

  5. 十招谷歌 Google 搜索

    十招谷歌搜索 一.或者 OR 二.网址 insite:example.com keyword 三.大约 1.类似查询(记得) ~keyword 2.模糊查询(记得) key*****word 3.模糊 ...

  6. Java_多线程

    线程(Thread) 1.线程是CPU进行资源调度的最小单位 2.线程是进程实际运行的单位,处理进程中无数的小任务 3.线程共享代码和数据空间 4.一个进程可以并发多个线程,线程之间切换系统开销很小 ...

  7. Libra的第一天

    wuli乖乖,今天是你降生第一天,以后的几年可能我们都会朝夕相处,你的成长就是我的向上,一起加油吧

  8. Github概念理解备忘录

    总结: add就是用来建立跟踪,添加文件到缓存区: commit就是把文件缓存区的文件正式加到本地库中: push就是把本地库更新到远程库中: git命令的操作要在仓库所在目录下进行才有效: 在Git ...

  9. FJWC2019 最短路

    题目描述 有一张无向图,开始的时候所有边权为1,所有点没有权值,现在给定一个整数k,表示可以将k个点的点权设置为1,求点0到n-1的最短路最长是多少 Solution 网络流好题[然而本蒟蒻还是不会] ...

  10. Zynq-7000 FreeRTOS(二)中断:串口Uart中断

    总结Zynq-7000器件的PS上的串口中断,为FreeRTOS中断实验做准备.