Keywords used by C + + for retouching

Source: Internet
Author: User
Tags volatile

1.const modifier pointer

(1)const int *P=&X: Cannot modify The contents of the *p, but can let the pointer p Point to another address, like int const *P

(2)int *const p=&x: The pointer itself is a constant, fixed to a variable, so p is immutable, but *p Variable

2.const modifier function

(1) before the function parameter , const is the protection pointer, the value passed by reference cannot be modified

(2) The member function of the class is followed by a const, the function cannot modify the member variable, the non- const member function cannot be called

3.Volatile

Access registers are much faster than accessing memory, and compilers tend to store frequently used variables in registers in order to ensure access speed, which can lead to dirty reading of variables. Volatile -Modified variables are read from memory every time, preventing dirty reads

4.Static

(1) hide. When we compile multiple files at the same time, all global variables and functions that do not have a static prefix have global visibility, so use the static Define a function with the same name and a variable of the same name in different files without worrying about naming conflicts.

(2) The second function of static is to keep the contents of a variable persistent. Variables stored in the static data area are initialized at the start of the program and are the only one initialized. A total of two variables are stored in static storage: Global variables and static variables.

(3) The third function of static is initialized to 0 by default . in fact, global variables also have this property, because global variables are also stored in the static data area. In the static data area, all bytes in memory default values are 0x, sometimes this feature can reduce the workload of the programmer.


Keywords used by C + + for retouching

Related Article

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.