Preface
As for pointers, we first need to figure out four points: the pointer type, the pointer to the type, the value of the pointer, and the value the pointer points to. If this is not very clear, please refer to here
URL:
ReadOnly allows you to set a field to a constant, but you can perform some operations to determine its initial value.Because ReadOnly is performed at the time of calculation, it can be initialized with certain variables, of course.ReadOnly are
A const member function, which can read the data members of a class, but cannot modify the data members of the class.1 statementAfter the parameter list declared by the member function, add the CONST keyword, declare it as a constant member function
The difference between the const, static, and readyonly keyword modifiers for C # is illustrated by a simple example:1 //SomeType.cs2 3 usingSystem;4 5 Public Sealed classSomeType6 {7 PublicInt32 Id =1;8 9 Public ConstInt32 ConstID =
C + + adds a const meaning to the function:In the member functions of the class we define, there are often some member functions that do not change the data members of the class, that is, the functions are "read Only" functions, and some functions
Like any other member, a Const member appears in three positions: global scope, common function, and class.See the test code for the front:1 # include "stdafx. h"2 # include 34 using namespace std;56 class7 {8 public:9 const int j;10 // const int k =
Const is a key word in C language. It specifies that a variable cannot be changed. Using const can improve the security and reliability of the program to a certain extent. In addition, it is helpful to understand the role of const while watching
(1) Example: 1. Int I = 1;Const int * cptr = & I;* Cptr = 2; // error. cptr points to constant 1.Cout 2. Int I = 1;Const int * cptr = & I;I = 2; // normalCout 3. Int I = 1, TT = 8;Const int * cptr = & I;Cptr = & tt; // normalCout To sum up, the only
Const is a key word in C language. It specifies that a variable cannot be changed. Using const can improve the security and reliability of the program to a certain extent. In addition, it is helpful to understand the role of const while watching
1. Const BasicsIf the const keyword does not involve pointers, we can understand it very well. The following is a case involving pointers:
Int B = 500;Const int * A = & B; [1]Int const * A = & B; [2]Int * const A = & B; [3]Const int * const A = & B;
Http://www.job168.com/info/read_79075.htmlPosting date: a const Basics
If the const keyword does not involve pointers, we can understand it very well. The following is a case involving pointers:
Int B = 500;
Const int * A = & B; [1]
Int const * A =
I. Const BasicsIf the const keyword does not involve pointers, we can understand it very well. The following is a case involving pointers:
Int B = 500;Const int * A = & B; [1]Int const * A = & B; [2]Int * const A = & B; [3]Const int * const A = &
Transferred from:
Http://www.newsmth.net/pc/pccon.php? Id = 10002714 & nid = 359712
Http://blog.csdn.net/Eric_Jo/article/details/4138548
Const Type Definition: indicates that the value of a variable or object cannot be updated. The purpose of this
[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]
Const is a keyword in C/C ++, but if it is used well, it can greatly improve the robustness of the Code.
The type of the pointer must be consistent with the object type it refers to allow pointers to constants to be obtained by a very mass object, to change values; A pointer to a constant does not specify that the object it refers to must be a constant
A const iterator, as the name implies, is an iterator that cannot be changed, and is a constant whose nature is determined by the Const. Let's say we define a const iterator like this.vectorint> VV (9); const vectorintis incorrect when the
0x01:const Constants1 Const int Ten ; 2 int 1 2 3 4 5 6 7 8 9 Ten }; 3 sizeof (a) // sizeof (a) isThe C + + compiler optimizes const, references constants, directly replaces constants, does not read memory, reads constant symbol tablesConst int Ten
const modifier Variable
One of the most common interview questions about Const is this: what is the difference between Char *const and const char*, and everyone knows that the const modifier represents a constant, that a const-modified variable,
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.