Define the difference between a macro definition and a const constant definition

Source: Internet
Author: User
Tags constant definition

Macro: Usually put some commonly used strings, basically leave the definition macro

1. Compile time is different: const is compiled at the time of compilation, the macro is compiled at the time of compilation (pre-compilation is the program load, Xcode will have a progress bar, show progress, this time is actually in pre-compilation)

2. Compile detection: const has compile detection, and macro does not compile detection

3. Benefits of Macros: You can define methods and functions

4. Macro Disadvantages: Large use of macros can lead to too long precompilation time

The role of the const

1.const is only used to modify the right variable (basic variable, pointer variable)

2. Const-Modified variables are read-only

For example:

After adding a const, A is read-only and cannot be assigned a value

Define the difference between a macro definition and a const constant definition

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.