Keyword const is used to define constants, if a variable is modified by the const, then its value can not be changed again, I think someone must have such a question, C language is not a #define, why do you have to use the const, I think the
1.const is used to modify ordinary variables, indicating constants, not recommended modifications, to a certain extent do not allow the modification (in fact, can be modified)Pointer constant: The pointer (the value of the variable pointed to)
This example describes the static and const keyword usages in PHP. Share to everyone for your reference, specific as follows:
The member properties and member functions that the static keyword describes in the class are static.
A static member can
1. Defining constants(1) The const modifier variable, the following two kinds of definition form are essentially the same. It means that the variable value of the type with the Const modifier is immutable.
TYPE const VALUENAME = value;
Const is a C + + language qualifier that restricts a variable from being allowed to change. The use of const can improve the security and reliability of the program to some extent. In addition, when looking at other people's code, clearly understand
Final keyword1. If we want a class to not be inherited by other classes (perhaps because of security considerations), you can use final.ExamplesFinal class a{} class extends a{}; // will error Echo "OK";? >2. If we want a method, such as a
Author: Wang Haining,Hua Qing vision embedded college lecturer.
During the C language tutorial, many students have a great misunderstanding about the keyword Const. I would like to summarize the misunderstanding of this keyword and hope to use the
#include usingnamespace std; void F (constint x) //const modifier function parameter, passed arguments cannot be changed within the function, Same as the nature of the above modified variable { x=3;//Compile error, cannot modify value of
//two usages of const-modified references#include using namespacestd;structteacher{Charname[ -]; intAge ;};voidSetA (ConstTeacher &T1) { //t1.age = 13; //Error C3490: cannot be modified because "age" is being accessed through a const
1. The const modifier variable, which indicates that the value of the variable does not change:Const TYPE ValueName = value;2. The pointer uses the const(1) The pointer itself is constant, with the following two types of notation:(char*) const pName;
"Reprint" Transfer from https://www.cnblogs.com/chogen/p/4574118.htmlConst is a C + + language qualifier that restricts a variable from being allowed to change. The use of const can improve the security and reliability of the program to some extent.
What is a const?
A constant type refers to a type that is described using the type modifier const, and the value of a variable or object of a constant type cannot be updated. (Of course, we can update cynical:)
Why the introduction of const?
The
Speech recognitionEr.xml Explorer open Penguin close Penguin shut down Restart notepad calculator drawing board Tan Sheng Yuyin.cpp#include #include #include
Reprint Please specify the source http://blog.csdn.net/xingjiarong/article/details/47282255Keyword const is used to define constants, if a variable is modified by const, then its value can no longer be changed, I think someone must have this
The static keyword is described in a class where member properties and member methods are static, and where are the benefits of static members? Before we declare the "person" of the human beings, in the class "people" if we add a "human state"
const int A;int const A;const int *a;int * const A;int const * a const;/******/The first two functions are the same, a is a constant integer number.The third means that a is a pointer to a constant integer number (that is, the integer number is not
Usage Environment:
You can use define to define constants in PHP, but you cannot use define in a class, and in a class, the values of some properties do not want to be modified, and we need to use Const to define constants.
How to use:
1, the
See effective C + + The second version of the recommended use of const, less use of define. It's not enough today to find out.#define定义的常量在预处理替换, the debug when the macro can not be printed, this constant setting is flawed, const definition
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
1. What is a const?Const means a constant type, a const-modified variable or object cannot be modified and updated, and of course, in some cases, we can change it rescue.2. Why should I introduce a const?The original purpose was to replace the
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.