• C语言、结构体 定义


    C语言允许用户自己建立由 不同类型数据组成的组合型数据结构 成为结构体。

    struct Student
    {
       int num;             //学号
       char name[20];       //姓名为字符串
       char sex;            //性别为字符型
       int age;             //年龄
       float score;         //成绩
       char add[30];       //地址为字符串
    
    };
    声明结构体 一般形式
    
    struct 结构体名
    {
    成员表列
    };

      定义结构体变量

    1先声明结构体类型 在定义
    struct Student  student1,student2;
    
    2 声明的同时定义变量
    struct Student
    {
       int num;             //学号
       char name[20];       //姓名为字符串
       char sex;            //性别为字符型
       int age;             //年龄
       float score;         //成绩
       char add[30];       //地址为字符串
    
    }student1,student2;
    
    //定义形式
    student 结构体名
    {
    成员表列
    }变量名表列;

      结构体变量初始化

       // 第一种
         struct student {
            char name[10];
            char sex;
            int age;
            char add[30];
            
        } student1 = {"sony",'m',20,"上城国际"};
    //第二种 struct student cc = {"liyang",'n',20,"上城国际"};
    //某一成员初始化 struct student ww = {.name = "sdasd"};

      结构体 数组

    //结构体数组
    
    ---定义1
       struct Person
        {
            char name[20];//姓名
            int age;    //年龄
        
        }leader[3] = {"zhangSan",20,"xiaoHua",19,"daYang",22};
    
    ----定义二
    struct Person leader[3] = {"zhangSan",20,"xiaoHua",19,"daYang",22};
    
    //定义结构体数组的一般形式;
    
    struct 结构体名
    {
    成员表列
    }数组名称[数组长度];

      结构体指针 (牛逼闪闪~~~)

    结构体指针:结构体变量的指针。

    指针变量存放 结构体变量的起始地址 指针变量 指向结构体变量

     

  • 相关阅读:
    Servlet 06: jar包引入和web配置文件创建
    Servlet 05: Servlet生命周期方法
    Servlet 04: 什么是重定向
    Servlet 03: 通过xml配置文件配置servlet访问路径
    080 面向过程编程
    079 内置函数
    078 匿名函数
    077 递归
    076 生成器
    075 字典生成式
  • 原文地址:https://www.cnblogs.com/ly1973/p/5953733.html
Copyright © 2020-2023  润新知