zoukankan      html  css  js  c++  java
  • 结构体类型定义(C语言)

    结构体的定义形式如下:

    struct 结构体名

    {

      结构体成员

    };

    结构体变量的定义方式有三种:
    1、先定义结构体,再定义变量:

    eg.

    struct student{

      char name[10];

      int age;

      int student_number;

    };

    struct student s1,s2;

    2、定义结构体的同时定义变量:
    eg.

    struct student{

      char name[10];

      int age;

      int student_number;

    }s1,s2;

    在定义结构体student的同时定义了结构体变量s1,s2.

    3、只定义结构体变量

    eg.

    struct{

      char name[10];

      int age;

      int student_number;

    }s1,s2;

    在这种情况下,如果还想定义一个变量s3,那么要使用和定义s1、s2一样的方法。

    将typedef和结构体结合,比如说:

    typedef struct _student{

      char name[10];

      int age;

      int student_number;

    }student;

    这个时候student就不是一个变量了,它是结构体struct _student的别名,如果想定义一个变量,就可以直接使用student

    student s1;

    而不需要struct _student s1;

    另外还可以定义结构体指针类型:

    typedef struct _student{

      char name[10];

      int age;

      int student_number;

    }*student;

    这个时候student s1;定义的变量就是一个结构体指针s1了。等价于struct _student *s1。

  • 相关阅读:
    .Net常用的命名空间
    Jquery测试纠错笔记
    第一章 学习总结
    Java和C++引用的区别
    gin的墙内开发艺术
    golang几个环境变量的问题
    Leetcode240_搜索二维矩阵II
    Leetcode1358_包含所有三种字符的子字符串数目
    Leetcode1354_多次求和构造目标数组
    Leetcode1353_最多可以参加的会议数目
  • 原文地址:https://www.cnblogs.com/winifred-tang94/p/5837401.html
Copyright © 2011-2022 走看看