C-Language custom data type (typedef)
The C language provides a function called TypeDef to declare a new name for an existing data type.
typedef int LENGTH;
Makes Length an alias of type int .
In this way, the length can be substituted for int appearing in defining variables and declaring functions where.
Length A, B;
Length A[10];
The name of the new type is the alias of the original type, which improves the readability of the program.
typedef struct {
int day;
int month;
int year;
} Date; Declares a struct type whose alias is date
Store
All the members share a space.
Only one member is valid at the same time.
The size of the Union is its largest member.
Initialization
Initializes the first member of a
Union anelt{
int i;
char c;
} anelt1,anelt2;
sizeof (Union ...) sizeof Maximum value per member
1#include <stdio.h>2 3typedef Union {4 inti; 5 Charch[sizeof(int)]; 6} CHI; 7 8 intMainintGrcConst Char*grv[])9 { TenChi, Chi; One inti; ACHI.I =1234; - for(i=0; i<sizeof(int) ; i++){ -printf"%02HHX", Chi.ch[i]); the } -printf"\ n"); - - return 0; +}
C Language Learning notes--type definition & Union