20151023-const, static, extern effect

Source: Internet
Author: User

1. What does the keyword const mean?

Const int A; int Const A; Const int *A; int Const *A; int Const A; int Const Const A;

The first two functions are the same: A is a constant integer number
The third and fourth means: A is a pointer to a constant integer number (the integer number is not modifiable, but the pointer can)
Fifth: A is a constant pointer to the number of shapes (the integer number pointed to by the pointer can be modified, but the pointer cannot be modified)
The last one means: A is a constant pointer to a constant number (the integer number pointed to by the pointer is not modifiable and the pointer is not modifiable)

2, the role of the static keyword

    • The static modifier function is an intrinsic function that can only be called in this file, and other files cannot be called;
    • The static modified global variable is an internal variable that can only be used in this file, and other files cannot be referenced by the extern keyword; (global variables are initialized only once, always reside in memory, and are destroyed when the program exits)
    • The static modified local variable is initialized only once, and the memory is reclaimed when the program exits.


3, the role of the keyword extern
extern indicates the keyword of the function and the scope of the global variable, which tells the compiler that its declared amount function or variable can be used in this module or in other modules.
extern just declares that it needs to be initialized somewhere else.
(It can also be said that extern can refer to a global variable declared elsewhere)

    • Note: This place is not clear, these three keywords of 1 and 32 keywords function after the perfect!!

20151023-const, static, extern effect

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.