zoukankan      html  css  js  c++  java
  • 【C语言】基础(十)结构体

    结构体

    面向对象里
    类(高级的封装)
    封装数据是什么
    封装数据做什么

    函数:逻辑的封装;
    结构体:数据模型的封装;

    枚举{1,2,3}
    联合体{int char double};选其中任一种类型

    变量定义
    struct student{
    int age; //成员列表;类型说明 标识符;
    char name[20];
    double mathscore;
    }A,B,C;
    struct student A;
    struct student B;

    初始化
    struct student A={15,"A",67}; 完全初始化
    struct student A={.name="A",.mathscore=67}; 部分初始化

    A.name="D";这样不行,字符串不能给字符数组赋值,应用strcpy,strcpy(A.name,“D”);
    A.age=18;结构体变量的赋值
    A=B;全部赋值;结构体之间的赋值


    结构体操作函数

    使用封装函数进行赋值。返回结构体。结构体接收
    struct student studentMakeWith(int age ,char* name,double mathscore);
    {
    struct student result;
    赋值;
    return result;
    }
    打印函数
    void showmessage(struct student stu);


    结构体指针
    struct Student* p;
    struct Student s1;
    使用结构体指针访问结构体成员变量
    p=&s1;
    p->age;
    p->name;

  • 相关阅读:
    Charles下载和使用
    C# mvc读取模板并修改上传到web
    nginx 安装
    python 测试:wraps
    Linux下MySQL数据库常用基本操作 一
    myeclipse新建maven项目
    java 数据导入xls
    tomcat允许跨域请求:
    Import Projects from git
    c# DataTable 序列化json
  • 原文地址:https://www.cnblogs.com/yujiamin/p/7371975.html
Copyright © 2011-2022 走看看