IOS--C 语言 Lesson Eight Struct

来源:互联网 发布:淘宝买家数据采集 编辑:程序博客网 时间:2024/06/05 12:07

一 结构体
1⃣结构体:结构体是一种用户自定义的数据类型
2⃣struct 结构体名{
成员变量类型1 成员变量名1;
成员变量类型2 成员变量名2;
3⃣ //1.struct + 结构体名
//2.成员变量要写在{}里
//3.每个成员变量用分号(;)
//4.大括号{}结束时也要用分号(;)

struct teacher{        char name[40];        int number;        char bust;        char pruduction[40];    };
  1. ypedef struct +变量名
    {
    数据修饰符 +变量名;(eg: int year )
    } 新变量名;
    typedef 结构体变量名 新的变量名(大驼峰命名法);

二 定义结构体变量
1⃣定义结构体变量

struct teacher teac = {"teacherCang",1,'F',"secondDream"};//struct teacher 是数据类型 //teac 是变量名 {"teacherCang",1,'F',"secondDream"} 初始值

2⃣访问结构体变量
输出teacherLuo的名
访问结构成员变量的属性是用 点语法 ,谁谁 的 的意思

printf("%s\n",teacherLuo.name);
0 0