The difference between typedef and define in C language

Source: Internet
Author: User

Today in C language practice involves the use of TypeDef and define problems, then what is the difference between them? Why use typedef in this case? In which case, why use define?

Did you ever think about it when you were studying C?

Today I decided to comb it for later use.

Same point:

1, you can give the variable alias

Different points:

1, define can be extended after definition, and typedef can not.

 1  //  2  3   #define  zhengxing int4  unsigned zhengxing; //  correct  5  int  7  unsigned zhengxing; //  error  
#行内代码
1// define an integral type after the data is added to the definition as unsigned
2 3 #define zhengxing int4 unsigned zhengxing; // correct 5 6 int 7 // Error

2, typedef can be defined continuously, define is not.

#define Apple char*//val1 is a pointer type char*, VAL2 is a char type.    char *//VAL1 and val2 are all pointer  types char*

Follow-up continues to add ...

The difference between typedef and define in C language

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.