Differences between typedef and define

Source: Internet
Author: User

Type alias. You can also define constants, variables, and compilation switches.

 

Both of them are the same in some cases.

However, define will be processed during pre-compilation for simple macro replacement. It will be replaced no matter whether it is correct or not. There will be no semicolons at the end, and even semicolons will be replaced together.

Typedef defines the alias in the defined type.

 

Typedef has a scope, and define can be used as long as it is defined

Typedef can not only define the built-in types of the system, but also define the user-defined type structure. The purpose of define is to take the alias of the definition type, as well as define constants, variables, and compilation switches.
Classic questions:
Const pint P; // P cannot be changed, but the content pointed to by P can be changed
Const pint P; // P can be changed, but the content pointed to by P cannot be changed.

Pint is a pointer type. Const pint P is used to lock the pointer. P cannot be changed.
The const pint P lock is the object referred to by the pointer p.



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.