Basic explanation
Const is a key word in C language. It specifies that a variable cannot be changed. The use of const can be improved to a certain extent.ProgramRobustness, In addition, watching othersCodeIt is helpful to understand the role of
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 first impression given by const is to define constants.
(1) const is used to define constants.
Example: const int n = 100; const int M = 200;In this way, as long as N and m are used in the program, they represent integer 100, 200, and N and M as
For pointers, you can specify the pointer itself as the const, or specify the data referred to by the pointer as the const, or both as the const, and neither of them as the const:
Char * P = "hello"; // non-const pointer, // non-const data const
Const detail in C + +From http://blog.csdn.net/lwbeyond/article/details/6187501I. The role of cons(1) const constants can be defined
const int max=100;
int Array[max];
(2) Can protect the modified things, prevent accidental
What is the role of the static keyword?Few people can answer this simple question completely. In the C language, the keyword static has three obvious functions:1. In the function body, a variable declared as static remains unchanged when the
Exploring the mysteries of C/C ++ arrays and pointers: pointer and const
The term const literally comes from the constant. The const object has different resolutions in C/C ++. As described in Chapter 2, constant expressions in C must be in the
C + + keyword Static,register,const,volatile,extern
Static variables are scoped to a file, space is allocated at the beginning of the program, Space is freed at the end, default is initialized to 0, and its value can be changed when used.
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:
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
http://blog.csdn.net/lzkit/article/details/7747741Refer to the contents of the book and some ideas on the forum to list the following const main usage:First, const and define.Both can be used to define constants, but the const definition defines the
1. When modifying constants:const int TEMP1; Temp1 is constant, not variableint const TEMP2; Temp2 is constant, not variable2. When modifying pointers:The main point of view is the const before and after the *, before the pointer to the content of
Experimental reasonsDescribes how to use the const description to protect class data from accidental modification.Compiling the environmentVC6SP6 + win7x64Project downloadCopyconstruction_constmemberfunction.zipCopy constructor error caused by using
The first impression given by const is to define constants.
(1) const is used to define constants.
Example: const int n = 100; const int M = 200;In this way, as long as N and m are used in the program, they represent integer 100, 200, and N and M as
11.1 use const to improve the robustness of functions
When you see the const keyword, C ++ programmers may first think of const constants. This is not a good conditioned reflection. If you only know that the constant is defined with const, it is
This article is mainly intended for C ++ learners who have misunderstandings about const syntax. I hope all those who are vague about this can read and find some answers..The earliest idea of const was to replace the macro of Preprocessor # define
Const is a C-language keyword that restricts a variable from being allowed to be changed. The use of const can improve the security and reliability of the program to a certain extent, and it can also help to understand the role of Const clearly when
The C + + ' const ' declaration:why & HowThe ' const ' system is one of the really messy features of C + +.It is simple in concept:variables declared with ' const ' added become constants and cannot are altered by the program. However it is also
Pre-knowledge1. Code Conversion Analysis Skillsin the early days some compilers translated C + + code into C code and then used the C compiler to build the executable file. One translation is to explicitly add the this pointer to the first parameter
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.