Loose-Info.com
Last Update 2012/07/05
TOP - C言語 - typedef

データ型に新しい名前を付けます。

typedef  型名   名前1 

型名 :
既存の型名
ポインタ、構造体でも可
名前1 :
型名に付ける新しい名前

(例)
#include <stdio.h> struct struct1 { int i1; int i2; }; typedef int int_test; typedef char *char_test; typedef struct struct1 struct_test; int main() { int_test i = 1; char_test c = "test"; struct_test s; s.i1 = 2; s.i2 = 3; printf("i = %d\n", i); printf("c = %s\n", c); printf("s.i1 = %d : s.i2 = %d\n", s.i1, s.i2); return 0; }

実行結果
i = 1 c = test s.i1 = 2 : s.i2 = 3