c_cpp C中的联合使用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp C中的联合使用相关的知识,希望对你有一定的参考价值。

#include "stdio.h"
#include "stdlib.h"

//c union example

typedef union
{
  long i64;
  int i32;
  short i16;
  char i8;
  
} Block;

typedef enum
{
  I64,
  I32,
  I16,
  I8
} Tag;



int main(void) {
  printf("sizeof block: %d\n", sizeof(Block));
  Block g;
  g.i8 = 46;
  printf("The char is %c\n", g.i8);
  printf("The number is %d\n", g.i8);
  printf("sizeof tag is %d", sizeof(Tag));
  return 0;
}

以上是关于c_cpp C中的联合使用的主要内容,如果未能解决你的问题,请参考以下文章