Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
TORU WAKAHARA<br />
《 注 意 》<br />
共 用 体 のサイズは, 最 も 大 きいメンバのサイズとなるが,コンパイラがワード 境 界 で<br />
そろえることがあり,sizeof 演 算 子 で 確 認 した 方 がよい。また, 一 度 に1つの 変 数 し<br />
か 使 用 できないことに 注 意 しよう。<br />
#include <br />
main()<br />
{<br />
union u_type {<br />
int i;<br />
char c[4];<br />
double d;<br />
} sample, *p;<br />
}<br />
p = &sample;<br />
sample.i = 1234;<br />
printf("int i : %d\n", sample.i);<br />
p->c[0] = 'O';<br />
p->c[1] = 'K';<br />
p->c[2] = '\0';<br />
printf("char c[4] : %s\n", sample.c);<br />
p->d = 12.34;<br />
printf("double d : %f\n", sample.d);<br />
printf("size of b_type = %d\n", sizeof(union u_type));