union uniontag{ datatype member 1; datatype member 2; ---- ---- datatype member n; };
union sample{ int a; float b; char c; };
union sample{ int a; float b; char c; }s;
union{ int a; float b; char c; }s;
union sample{ int a; float b; char c; }; union sample s;
#include <stdio.h> union pointer { int num; char a; }; int main(){ union pointer p1; p1.num = 75; // p2 is a pointer to union p1 union pointer* p2 = &p1; // Accessing union members using pointer printf("%d %c", p2->num, p2->a); return 0; }
75 K
#include <stdio.h> union pointer { int num; char a; }; int main(){ union pointer p1; p1.num = 90; // p2 is a pointer to union p1 union pointer* p2 = &p1; // Accessing union members using pointer printf("%d %c", p2->num, p2->a); return 0; }
90 Z
以上がC言語で共用体ポインタを説明するの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。