Needless to say, please see the following procedure:
#include <iostream>using namespace std; #define SIGN1 char* //typedef char * sign2;//typedef is a statement so end with a semicolon int Main () {SIGN1 ch1,ch2; SIGN2 ch3,ch4;cout<<sizeof (CH1) << "" <<sizeof (CH2) <<endl;cout<<sizeof (CH3) << " "<<sizeof (CH4) <<endl;return 0;}
think about what the answer is???
#define宏替换只是 Simple Replacement : (completed at preprocessing) (the preprocessing command begins with #, with no semicolon at the end, because they are not statements)
SIGN1 CH1,CH2; ----------->>>> char * CH1,CH2;
CH1 is a pointer (char *) four bytes CH2 type char one byte
typedef type Rename, named identifiers have the function of type definition description ( compile-time processing) (is a statement, so end with a semicolon)
SIGN2 CH3,CH4; ----------->>>> char * CH3,*CH4;
CH3 and CH4 are pointers.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[C + +] introduces the difference between # define and typedef through a simple program