The custom type name must be capitalized to indicate that this is a custom type.
1. Rename unsigned long to uint:
# Include <stdio. h> int main (void) {typedef unsigned long uint; uint num = 1234567890; printf ("% lu \ n", num); getchar (); Return 0 ;}
2. rename a structure:
# Include <stdio. h> int main (void) {struct rec {char C; int I; long d ;}; typedef struct rec myrec; myrec R1; r1.c = 1; r1. I = 2; r1.d = 3; printf ("% d, % d, % d \ n", r1.c, r1. I, r1.d); printf ("structure size: % u, % u, % u ", sizeof (struct REC), sizeof R1, sizeof (myrec); getchar (); Return 0 ;}
3. Define the integer pointer as: pint:
# Include <stdio. h> int main (void) {typedef int * pint; int num = 123; pint P = & num; printf ("% d, % P \ D", * P, p); getchar (); Return 0 ;}
4. Used for structure definition at the same time:
# Include <stdio. h> int main (void) {struct rec1 {int X, Y;} R1 = {11, 22 }; /* simultaneously defines the variable R1 */typedef struct rec2 {double A, B;} rec3;/* at this time, rec3 is not a variable, it is a newly defined type */rec3 r2 = {1.1, 2.2}; printf ("% d, % d \ n", sizeof (struct rec1), sizeof (struct rec2 )); printf ("% d, % d, % d \ n", sizeof (rec3), sizeof R1, sizeof R2); printf ("\ n % d, % d ", r1.x, r1.y); printf ("\ n % G, % G", r2.a, r2. B); getchar (); Return 0 ;}