c 語言typedef 和 define的使用和區別

來源:互聯網
上載者:User

標籤:ring   編譯器   .com   clu   har   div   color   名稱   bsp   

 #define是C的指令,用於為各種資料類型定義別名,與typedef 類似,但是有一下幾點不同

 1,typedef僅限於為類型定義符號名稱,而#define不僅可以為類型定義符號名稱,也能為數值定義別名,比如可以定義1為TRUE;

2,typedef是由編譯器執行解釋的,#define是由先行編譯器進行處理的。

 

#include "stdafx.h"#include "string.h";#define TRUE 1#define FLASE 0typedef  char BYTE;int main(){    printf("TRUE= %d\n",TRUE);    printf("FLASE= %d\n", FLASE);    BYTE a, b;    a = 100;    b = 102;    printf("a= %d\n",a);    printf("b= %d\n",b);}

運行結果:

 

c 語言typedef 和 define的使用和區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.