(简单)宏定义 与 用户自定义类型typedef

宏定义(宏替换)

    #define   标识符   被替换信息

例:<1> #define   P   printf("

        ......

        P%d,%d",a,b); //printf("%d,%d",a,b);

       ......

    <2> #define   Max(x,y)   ((x)>(y)?(x):(y))

    <3> #define   TURE   1

        #define   FALSE   0

  

    总结:1.宏替换不能改变运算量

          2.提高程序的可维护性

          3.提高程序的可读性


用户自定义类型  typedef

    #define   已有类型   新类型名称

例: typedef   int   Integer; //int  a; <==> Integer  a;

     typedef   struct   Student_Information   ST;


   typedef常与struct联合使用,以简化结构体类型的书写!

          Typedef   struct   STINF{

               ............

           }STINF;//结构体实例名称

                      STINF   a ,b[50] ,*p; // <==> struct   STINF   a ,b[50] ,*p;


用户自定义类型typedef 延伸

     typedef   char   *CHP <==> typedef   char*   CHP

     typedef   char   CHA[10] <==> typedef   char[10]   CHA


         CHP   a1 ,*b1 ,c1[10];<==> char   *a1; char   **b1; char   *c1[10];

         // CHP  c1[10]:  char*  c1[10] <==>char  *c1[10]指针数组


         CHA   a2 ,*b2 ,c2[20];<==> char   a2[10]; char   *b2[10]; char   c2[20][10];

       // CHA  *b2:  char[10]  *b2 <==> char  *b2[10] <==> char*  b2[10] { 错误 }

                       char[10]  *b2 <==>char  (*b2)[10] 数组指针<==> char[10]  *b2{ 正确 }

       // CHA  c2[20]:  char[10]  c2[20] <==> char  c2[10][20] <==> char[20]  c2[10]{ 错误 }

                         char[10]  c2[20] <==> char  c2[20][10] <==> char[10]  c2[20]{ 正确 }

    综上:typedef语句可以“构造”复杂的数据类型!


#define语句 和 typedef语句

         

          #define   X   char*

            typedef   char   *Y

                 X   a ,b ,c; <==>char   *a ,b ,c;

                 Y   a ,b ,c; <==>char   *a ,*b ,*c;

              


                      





       


     


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值