C/C++ 언어 union(공용체)를 이용한 예제 프로그램


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* 공용체를 이용한 예제 프로그램 */
#include <stdio.h>
union number {
  int x;
  float y;
};
 
void main(void)
{
  union number value;
 
  value.x = 100;
  printf("%s\n%s\n%s %d\n%s %f\n\n"
    "Put a value in the integer member",
    "and print both member.",
    "int :  ", value.x,
    "float : ", value.y);
  value.y = 100.0;
  printf("%s\n%s\n%s %d\n%s %f\n\n"
    "Put a value in the floating member",
    "and print both member.",
    "int :  ", value.x,
    "float : ", value.y);
}
 
cs


C/C++ 언어 union(공용체)를 이용한 예제 프로그램



+ Recent posts