Random 1 (#define a 10 and const int a=10)

Source: Internet
Author: User

It is the high season of the job-writing, a few days ago heard that someone encountered this problem: #define A 10 and the const int a=10 difference, nonsense said, below to explain:

#define directive is to define symbolic constants

Const defines a constant variable (the value of a variable cannot be changed)

Symbolic constants simply replace a string with a symbolic constant, which is replaced at the time of precompilation. There is no type, and in memory there is no memory cell with a long symbolic name;

The variable is of the type, and in memory there is a memory unit named after it, and it is possible to measure his length with sizeof.

The difference above means that the first A is of no type and is a symbolic constant

And the second A is of type int, a variable that cannot be changed by a value

OK, do you understand?

Random 1 (#define a 10 and const int a=10)

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.