1. Replace # define. When it comes to using const instead of # define, why do you do it, of course, Const is better than # define, and one obvious difference is that const has a data type that can perform type safety checks, while # define is
Const, a read-only variable in C LanguageRead-Only variable, so that the value of the variable cannot be changed.Const is a key word in C language. It specifies that a variable cannot be changed. Using const can improve the robustness of the program
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 equivalent to using gunpowder only to make firecrackers.
The const modifier can convert an object to a constant object. What does it mean? That is to say, the value of the variable modified using const cannot be modified at any position of the program, just like a constant. A good program has a very high
First look at a piece of C code (Note: If you compile this code in vs, you need to set the suffix to. c instead of. cpp, because the suffix name is c, vs will use the C compiler)# Include
Int main (int argc, const char * argv [])
{
// In C, const
1. As long as this (a value remains the same) is true, it should be really said, so that you can get the help of the compiler to ensure that this constraint is not violated.2.keyword const can be used in many ways, but it is easy to use.2.1classes
Const, static, extern usage summary, constextern
Const application:
1. For the basic declaration const int r = 100; // standard const variable declaration and initialization, the compiler will directly replace it with 100 during compilation after
Objective
This article mainly describes how to use CONST,STATIC,EXTERN3 in the development of keywords, if you like my article, you can pay attention to my microblog: Acridine a Zheng, you can also come to small code brother, understand our iOS
Const usage summary:
I. Const and pointerJudgment Rules:If the const is on the left side of the asterisk, the const is used to modify the variable pointed to by the pointer, that is, the variable referred to by the pointer cannot be modified;If the
First look at const int a = 2; the value of a is read-only.
The difference between const int * p and int * const p ,.
It can be understood as follows: divide the variable into two parts based on the "*" as the demarcation point to see who the const
Const, static, extern introduction, constexternConst, static, extern Introduction 1. Difference Between const and macro:
Const Introduction: the commonly used string constants are generally extracted into macros, but apple does not recommend that
C + + const allows you to specify a semantic constraint that the compiler enforces to allow the programmer to tell the compiler that a value is unchanged. If you do have a value in your programming that remains unchanged, you should explicitly use
I have learned C ++ for a long time, but I have never been able to write c ++ code, so many things have been forgotten. During my vacation, I found C ++ learning materials to review and write down some study notes for my future review. The following
IOS development: Correct Use of const, static, and extern
Preface
This article mainly describes how to use the const, static, and extern3 keywords in development. If you like my article, you can follow my weibo blog: I have a problem, or you can
Read it backwards (as driven by clockwise/spiral Rule) ...
int*-Pointer to int
int const *-Pointer to const INT
int * const-Const pointer to int
int const * const-const pointer to const INT
Now the first const can is on
The return type of C + + functions, including when does const work?
The function return value does not want it to be modified immediately.
As an example, this is a simple way to avoid the creation of the invisible return variable, 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,
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
When I first came into contact with const, I simply remembered that the variable modified by const was a constant. However, this is far from the case of Const.
I. Primary part
1. Use const as the qualifier
(1) Modify common variables and define the
As with a reference, you can make the pointer point to a constant or to a very great amount. A pointer to a constant cannot be used to change the value of the object it refers to. The address of the constant object you want to store. You can only
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.