const keyword
/***********************c++ Const characteristic Analysis *********************/
#include
using namespace std;
Class a{
private:
int A;
Public:
A () {}
a (int A) {a::a = A;}
void SetA (const int& a) {
a::a = A;
}
The
readonly keyword differs from the const keyword.">The ReadOnly keyword differs from the const keyword. the const field can only be initialized at the declaration of the field."> const field can only be initialized in the declaration of the field.
3.2.2 Constantsand variables can be used in the program to express those that may change the amount of data corresponding to, in C + +, we use constants to express those always remain unchanged data volume. In simple terms, the values, characters,
3.2.2 Constantsand variables can be used in the program to express those that may change the amount of data corresponding to, in C + +, we use constants to express those always remain unchanged data volume. In simple terms, the values, characters,
Why use Const. Code written in symbolic constants is easier to maintain; pointers are often moved by side-reading, rather than by writing; many function parameters are read-only and not written. The most common use of const is as the bounds of the
Const Type Definition: indicates that the value of a variable or object cannot be updated. The purpose of this definition is to replace the precompiled command.
×××××× Constant must be initialized.
Role of const
A can define const constants,
Const int myconstant = 10
An int which can't change value. Similar to # define in C but better.
Const int * myconstant
Variable pointer to a constant integer.
Int const * myconstant
Same as abve.
Int * const myconstant
There are several cases where the const and the pointer are together.Const int*P1;//indicates that the P1 itself is not const, and that the variable pointed to is const.Const*intP2;//syntax errorint Const*P3;//indicates that the P3 itself is not
Why use const? Code written with symbolic constants is easier to maintain, and pointers are often moved along the edge of the read side, rather than the edge-write edges, and many function parameters are read-only and not written. The most common
The const object defaults to the local variable of the file, unlike other variables, unless it is specifically stated that the object's file local variables are defined when the const variable of the global scope. This variable exists only in that
Understand the Static and Const keywords in PHP5. PHP5 has added a lot of object-oriented ideas. PHP5's object-oriented thinking is closer to Java's object-oriented thinking. Here we will describe the role of static and const in PHP5. I hope PHP5
Class Counter
{
private static $count = 0;//defines a static property
Const VERSION = 2.0;//defines a constant
constructor function
function __construct () {
Self:: $count + +;
}
Destructors
The concept of const is a variable that contains unchangeable values.Constant expressions are fully computed during compilation. Therefore, constants cannot be initialized by extracting values from a variable.If const int A = B + 1; B is a variable,
ConstKeywords:
The definition object modified with const is called a constant object;
Declaring a member function modified by const is called a member function;
The declared data member modified by const is a common data member.
After a variable or
In C ++, the const qualifier is used to define constants. However, const can appear in the definition of constants or methods, and the positions of const are also different, the meanings are also different.
Use const whenever possible. Add the
I. Storage Area of C language programs
1. an executable program (binary file) is formed by C language code (text file). Three phases are required: compilation, assembly, and connection. In the compilation process, C language text files are used to
Application of 14.final Keywords
This keyword can only be used to define classes and define methods, and you cannot use the final keyword to define member properties because
For final is the meaning of constants, we define constants in PHP using the
Const defines a variable that is not allowed to be changed to produce a static effect. Using const can improve the security and reliability of the program to some extent. One, const modifier variable
const int n=5;int const n=5;
These two kinds of
Preface The const keyword is a constant rhetoric. To tell the compiler that a variable will not change in the program, you can declare it as Const. However, the limit on the const keyword cannot just stay at this layer-it provides many more
Use of const in C:Although it sounds very simple, in fact, the use of const is also a subtle place in C language, where is the subtlety? See the following questions.Problem: const variable & ConstantThe following example uses a const variable to
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.