공부/C언어

19. union 응용

유저라인 2019. 7. 8. 13:49
728x90
반응형

main.c

#include <stdio.h>

union converter { 
 float f_val; 
 short u_val[2]; 
}; 

void main(void) { 
 float test1 = 40.26; 

 union converter conv; 

 conv.f_val = test1; 
 printf("%x %x\r\n", conv.u_val[1], conv.u_val[0]); 
}

union은 메모리를 공유하는 구조 입니다.

float 는 4바이트..short는 2바이트 입니다.

float ㅁㅁ ㅁㅁ

u_valㅁㅁ ㅁㅁ

 

이런식입니다.

 

결과 화면

728x90
반응형