Const and violate

Source: Internet
Author: User

Const modifier variable

in C,aconst -Modified variable is read-only, essentially a variable, and the modified variable takes up space in memory (that's nonsense), which is inherently const only useful to compilers, Useless at run time. the const and type Order are not required, the generic type is before, andtheconst is behind.

The const- modified array is read-only and the decorated array space cannot be changed.

const int* p; P variable, pointing to content is immutable

int const* p; P variable, pointing to content is immutable

int* Conse p; P is immutable,p points to content variable

Const int* Const p//p and p point to immutable content

Formula: Left digit right finger

when const appears to the left of the * number, the data pointed to by the pointer is constant

The pointer itself is constant when const appears to the right of the * number

Const modifier function parameters and return values

The const modifier function parameter indicates that the value of the parameter is not expected to change in the body of the function, andtheconst indicates that the return value is immutable and is used to return the pointer.

const int * FUNC ()

{

static int count = 0;

count++;

Return &count;

}

Volatile can be interpreted as "compiler warning indicator word"

Used to tell the compiler that every time a variable value is removed from memory, it is used primarily to decorate variables that may be accessed by multiple threads, or to modify variables that may be changed by unknown factors. If a variable is an rvalue for a long time, it is easily replaced with a constant.

Const and violate

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.