结构体
weixin_46060711
c/c++
展开
-
使用结构体传值
使用结构体传值:1.形参是结构体变量,值传递#include <stdio.h> #include <stdlib.h> #include <string.h> struct programer{ char name[32]; int age; int salary; };//形参是结构体变量,值传递 struct programer add_salary1(struct programer p, int num){ p.salary原创 2021-12-18 15:45:59 · 699 阅读 · 0 评论 -
指向结构体的指针
使用结构体变量址指针访问结构体成员要使用 -> 符号#include <stdio.h> #include <stdlib.h> #include <string.h> struct _friend{ char name[32]; char sex; // 'm'表示男 'f'表示女 int age; };int main(void){ struct _friend girl = {"小龙女", 'f', 18}; struct原创 2021-12-18 15:14:21 · 219 阅读 · 0 评论 -
结构体的数组
结构数组 (也就是结构体的数组)的组成:struct 结构名 变量名[数组大小]#include <stdio.h> #include <stdlib.h> #include <string.h> struct student { char name[16]; int age; };int main(void){ struct student s[2]; printf("请输入第一个学生的姓名:\n"); scanf_原创 2021-12-18 15:03:04 · 398 阅读 · 0 评论 -
结构体的定义,初始化及使用
1 为什么要使用“结构”(结构体)需要表示一些复杂信息时,使用单纯的数据类型很不方便。比如:学生信息(学号,姓名,班级,电话,年龄)2 什么是“结构”结构,就是程序员自定义的一种“数据类型” 是使用多个基本数据类型、或者其他结构,组合而成的一种新的“数据类型”。3 结构的定义struct 结构名 { 成员类型 成员名; 成员类型 成员名; };示例:(表示学生信息(姓名,班级,电话,年龄))struct student { char name[16]; int age;原创 2021-12-18 14:53:39 · 237 阅读 · 0 评论