C language const, static, static const difference

Source: Internet
Author: User

Basic definition:

Const is a read-only meaning and is used only in declarations;
static generally has 2 functions, which specify scope and storage mode .

For local variables, static is defined as static storage , the initial value of each invocation is the value of the last call, and the storage space is not released after the call is finished ;
For global variables, this variable is only visible in the current file if the scope is scoped to the file . For the static function is also visible within the current module function .
The static const should be a collection of the two above.

PS:
1. Global
Const, a read-only global variable whose value cannot be modified.
static, which specifies that this global variable is visible only in the current module (file).
The static const is both read-only and visible only in the current module.
2. Documents
The file pointer can be viewed as a variable, similar to the one described above.
3. Functions
Const, a function that returns a read-only variable.
static, which specifies that the function is visible only in the current module.
4. Class
const, generally do not modify the class, (in the VC6.0 test, the modification of the class does not work)
there seems to be no static class in the static,c++, generally still take class as a special variable to see. There is a detailed description of the static class in C #, and the usage is very different from the normal class.

C language const, static, static const difference

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.