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

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

    笨鸟先飞
  • 相关阅读:
    Handler使用入门 下载文件
    基于QT前端的mplayer播放器2
    HTTP协议详解(真的很经典)
    安装 gentoo minimal cd
    linux 分区方案
    MFC 中添加按钮和事件
    makefile 学习
    堆和栈
    paste命令使用
    cut用法
  • 原文地址:https://www.cnblogs.com/zoutingrong/p/12199382.html
Copyright © 2011-2022 走看看