IOS开发---C语言-⑮结构体

来源:互联网 发布:mac桌面贴便签 编辑:程序博客网 时间:2024/06/05 15:34

1.结构体的定义


它的定义方式:

定义变量的第1种方式:
     // 1.类型
     struct Student
     {
     int age;
     double height;
     char *name;
     };
     
     // 2.变量
     struct Student stu = {20, 1.78, "jack"};

定义变量的第2种方式:定义类型的同时定义变量
    /*
     struct Student
     {
     int age;
     double height;
     char *name;
     } stu;
     
     struct Student stu2;

定义结构体变量的第3种方式:不能重用,不建议使用(没有名称)
    struct {
        int age;
        char *name;
    } stu;
    
    struct {
        int age;
        char *name;
    } stu2;
    
    
    /*错误写法:结构体类型不能重复定义
     struct Student
     {
     int age;
     };
     
     struct Student
     {
     double height;
     };
     
     struct Student stu;
     */
    
    /* 错误写法:结构体类型重复定义
     struct Student
     {
     int age;
     double height;
     char *name;
     } stu;
     
     struct Student
     {
     int age;
     double height;
     char *name;
     } stu2;c
     */
    
    /*


2.结构体定义时的注意



3.结构体在内存中的存储形式(补齐算法)



0 0