Programmer --- C language details 21 (# difference between define and typedef, structure details)
Main Content: # difference between define and typedef, struct details
# Include
# Define INT_D int * # define CHAR_D char int main () {/* # difference between define and typedef */typedef int * INT_T; typedef char CHAR_T; INT_T a, B; // both a and B are int-type pointers INT_D c and d; // c is int-type pointers and d is int-type Integer unsigned CHAR_D e; /// the define type definition can be extended. // unsigned CHAR_T f; // This sentence is incorrect, type Def redefinition type cannot be added with Type Extension/* structure details * // Test 1 struct foo {int foo;} foo; // The final foo is a variable declared by the structure foo // foo test; // it is incorrect to define a structure directly like this foo. foo = 1; // The struct name can be the same as the internal variable name printf ("foo = % d \ n", foo. foo); // Test 2 typedef struct fun {int fun;} fun; fun fn; // can be defined at this time/* Conclusion: 1. Do not use typedef for struct for convenience, the only advantage is that you do not need to write struct, but this keyword can prompt you with some information, which should not be omitted. 2. typedef is used in arrays, structures, pointers, and function combination types; portable type. When you need a type of at least 20 bits, you can perform the typedef operation. In this way, when the code is transplanted to an inaccessible platform, you need to select the correct types such as short, int, and long, you only need to modify typedef, instead of modifying each type */return 0 ;}
Output: