Reference: http://www.weixueyuan.net/view/6348.htmlSummarize: The initialization of const member variables has only one path: the parameter initialization table.The const member function can use all member variables in the class, but cannot modify
Const keyword and pointer, const keyword pointer
Four cases of const and pointer combination
The four situations are as follows:
Int cons * p itself is not a constant, and p points to the address of the data is a constant
Const int * p itself is
//the const keyword in a class#include using namespacestd;classpoint{ Public: //This const keyword essentially modifies the this pointer intGetX ()Const //====>int GetX (const this) { //because this is hidden, the const keyword has
The const keyword exists in both C and C ++ languages. Many people have a wrong idea about this keyword. In C, the const keyword is used to make the variable as a constant, variable normalization is like macro definition. In C, the keyword
First, #define宏定义1. Macro definition, like this is the macro definition: #define PI 3.14159;2. Macro Definition Format: Macro value #define Macro name is the macro to be defined, usually denoted by a meaningful name in uppercase, and the macro value
The const keyword is used in C + + to modify constants, which are summarized in two ways: variables and member functions.Variables: const can modify ordinary variables, pointers (arrays), and structs.1.const modification of common variables is the
semantics of the const keyword
Simply put, the const keyword will decorate a quantity as "constant", that is, the amount of non-volatile. This amount can be a basic type variable, a class object, a pointer, an object reference, a class member
Const keyword in C Language
Author: silent lambs
Const keyword in C language:
-- Features.
Variables that use this key modifier cannot be changed.
-- Pointer constant.
Demo:
Const char * p or char const * p
-- Constant pointer.
Demo:
Char *
In general, the constkeyword is not used to differentiate the type of data, and in the declaration process, it acts as a cosmetic qualifier.1 symbolic constants (usually, the values cannot be changed after the initial value is assigned, whereas
The Const keyword is common in C code, and the following summarizes its role:1. Declare a variable as constant, which is read-only. This is similar to # define, such as: const int A;At this time, a is considered a constant, with an immutable nature.
Const keyword, const
Problem proposal
Analyze the following definitions:
const char* p1;char const* p2;char* const p3;const char** p4;char const** p5;char* const* p6;char** const p7;
There are no problems with the first three in 90%. Many
In C, the purpose of the const keyword is to keep the variable value modified during function operations. We usually see the following const usage, which seems to be summarized as "proximity principle": that is, the variable closest to the right of
In es6, The let keyword and the const keyword are provided.
The declaration method of let is the same as that of VaR. Instead of VaR, let can be used to declare the variable, so that the variable can be restricted to the current code block.
When
: This article mainly introduces the use of the const keyword in the PHP program. if you are interested in the PHP Tutorial, please refer to it. Environment:
In PHP, define can be used to define constants, but define cannot be used in classes. in
The const keyword is used to denote a variable or function, or another type of data whose value or its own value is prohibited from being modified.However, it is important to note that even if the variable is modified to a const type, its nature is
Defined
The Const keyword is scoped to the type of the variable. The value of a const-modified variable cannot be changed (it can no longer be assigned after initialization), for example:const int NUM1 = 1;NUM1 = 1; Errorconst indicates that
The const keyword does not represent a constant, but "the content cannot be modified ". The variable modified by const does not necessarily have the same value. It may be changed by external conditions that cannot be detected by the compiler. Const
The const keyword can not only modify variables, but also modify the parameters, return values, and even definitions of functions.
1. Modify Variables
Const char var; // It indicates that the VaR variable is now "Read-Only variable", and any
You see the const keyword, most people will not think it is a const constant, I tell you that this is wrong cognition, then what is the actual meaning of it? In fact, a const cannot change a variable to a constant, but rather a variable into a
Silent LambC Language const keyword: --Features. variables that use this key modifier cannot be changed . --pointer constant. Demo: const char *P or char const * P --constant pointer. Demo:char * Const P--constant pointer and pointer constant.
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.