The difference between the sum typedef define c language of

Macro definition simply string substitution, the pretreatment is completed, the process is typedef at compile time, it is not as simple substitution, but to re-order the type specifier. Named has a function type definition identifiers described.

#include <stdio.h> 
#include <the iostream>
 #define PIN1 char * 
typedef char * PIN2; 

int main () {
     // Use #define equivalent: char * x, y; x is a char that is a pointer type, and y is a char type 
    PIN1 x, y;
     // using typedef equivalent: char * x, char * y ; x is a char that is a pointer type, and y is char pointer type 
    PIN2 A, B; 
    the printf ( " By #define: % D% D \ n-\ n- " , the sizeof (X), the sizeof (Y)); 
    the printf ( " By typedef:% D% D \ n-\ n- " , the sizeof (A), the sizeof (B)); 
    System ( "pause");
    return 0;
}

Output:

Guess you like

Origin www.cnblogs.com/xiximayou/p/12128552.html