zoukankan      html  css  js  c++  java
  • 2. 结构体

    1. Struct结构体:一系列声明
      (1)结构中定义的变量称为成员
      (2).或->可以读取结构体中成员的值。.和->的优先级最高,要高于++,*等操作符

      // define替换结构体明
      #include <stdio.h>        
      #define NN struct nn
      NN {
          unsigned int is_keyword;
          unsigned int is_static;
      } nn;
      main(){
          NN mynn = {0,12};
          printf("%d",mynn.is_static);
      }
      
      
      // 结构体声明同事定义
      #include <stdio.h>                                                                                  
      main(){
          struct NN{
                  unsigned int is_keyword;
                  unsigned int is_static;
          } nn = {0,12};  // 声明时直接定义;另起一行nn={0,12}错误
          printf("%d",nn.is_static);
      }
      ~  
      
      // 声明定义区分
      #include <stdio.h>        
      struct NN { 
          unsigned int is_keyword;
          unsigned int is_static;
      } ;     
      main(){ 
          struct NN mynn = {0,12};
          printf("%d",mynn.is_static);                                                                    
      } 
      
    2. sizeof函数
      (1)sizeof()计算变量或变量对应类型的存储字节数
      (2)sizeof返回无符号类型的size_t类型,该类型在stddef.h中有定义

    3. typedef关键字
      (1)typedef定义新的类型名(给已有类型加类型名)

    4. union联合变量
      联合变量也是多种类型变量的声明,但是union变量申请的内存大小是3中类型中占地最长的那个

      union u_tag{
          int ival;
          float fval;
          char *sval;
      } u ;
      
  • 相关阅读:
    省选模拟24 题解
    省选模拟23 题解
    省选模拟22 题解
    省选模拟21 题解
    省选模拟20 题解
    省选模拟19 题解
    省选模拟18 题解
    源码分析工具
    深入理解js的变量提升和函数提升
    python并发编程之IO模型
  • 原文地址:https://www.cnblogs.com/72808ljup/p/5611360.html
Copyright © 2011-2022 走看看