zoukankan      html  css  js  c++  java
  • 结构体的四种定义方法

    1.先定义结构体类型,再定义结构体变量

    struct student{

    int data;

    };

    struct student stu1;//stu1为student的结构体变量

    2.定义结构体变量的同时,定义结构体变量

    struct student{

    int data;

    }stu1;

    如果想要继续定义结构体变量

    struct student stu2;//这样既可以再次定义结构体变量

    3.不定义结构体类型,而直接定义结构体变量

    struct{

    int data;

    }stu1;

    这样做的缺陷很大,这样的话我们就不能再次定义stu1该类型的结构体变量了,可移植性非常差,也不灵活。

    4.用typedef 来定义结构体变量及类型

    typedef sturct node{

    int data;

    }Binode;

    这样定义的话,结构体类型的名字就有了两个分别为node和Binode

    自然定义结构体变量的方式也就有了两种

    1.struct node val1

    2.Binode val2

    我在写代码时一般采用该种方法,个人喜好。

    笨鸟先飞
  • 相关阅读:
    aidl 详解
    为什么我选择用 flutter
    hunting
    Dynamic programming
    android 微信开发交流群
    hash function 字符串哈希函数
    函数也可以看成是空间的变换
    语法树
    生活中的物理随处可见
    about coroutine
  • 原文地址:https://www.cnblogs.com/zoutingrong/p/12199382.html
Copyright © 2011-2022 走看看