The use and difference of C-language typedef and define

Source: Internet
Author: User

#define是C的指令, used to define aliases for various data types, similar to TypeDef, but with a few different

1,typedef is limited to defining a symbol name for a type, and # define can define not only the symbol name for the type, but also the alias for the value, such as 1 to true;

The 2,typedef is interpreted by the compiler, #define是由预编译器进行处理的.

#include"stdafx.h"#include"string.h";#defineTRUE 1#defineFlase 0typedefCharBYTE;intMain () {printf ("true=%d\n", TRUE); printf ("flase=%d\n", flase);    BYTE A, B; A= -; b=102; printf ("a=%d\n", a); printf ("b=%d\n", b);}

Operation Result:

The use and difference of C-language typedef and define

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.