In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "A brief introduction of variables and pointers in C++". In daily operation, I believe many people have doubts about the brief introduction of variables and pointers in C++. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "brief introduction of variables and pointers in C++". Next, please follow the editor to study!
Variable
The basic form of a variable is a type specifier followed by a list of one or more variable names separated by a comma and ending with a semicolon.
Int sum = 0string bot first_name,last_name
Variable naming convention:
(1) variable names are generally in lowercase letters
(2) Custom class names are generally capitalized
(3) if the variable name consists of multiple words, it is better to have a clear distinction between the words.
Quote
A reference is another name for an object, and all references are not objects, but just another name for an existing object that defines the reference type in the form of a declaration as &.
Student student ("baxiang", 26); Student & refStudent = student; student.show (); refStudent.show ()
A variable declared as a reference must be initialized, but the initialized value must be an object.
String & rName = "test1"; / / error
In general, during initialization, the initialization value is copied to the new object, and the reference object is initialized with the referenced object, rather than copying a new initialization to the reference, that is, the reference shares a memory address with the referenced object.
String name = "test"; string & rName = name; string & othName = rName; pointer
Similar to references, pointers also implement an indirect access to other objects, defining pointers by putting an asterisk before the variable *
Int * value,*result;float * height
The pointer stores the address information of the object. To get the address of the object, you need to use the address character &
String test = "test"; string * testPoint = & test
If the pointer points to an object, you need to access the currently pointed object by dereferencing the symbol (*)
Const qualifier
We sometimes hope that the value of the variable we define cannot be modified. To meet this requirement, we can use the keyword const to restrict the variable type.
When the const variable is encountered when the program is compiled, it will be replaced with the corresponding value where the variable is used, that is, the compiler will find the use of buffSize and replace it with 1024.
By default, the const variable is set to be valid only within the file, and when a const variable with the same name appears in multiple files, separate const variables are actually defined in different files. If you need to implement file sharing, we don't want the compiler to generate separate variables for each file, that is, to declare that other files are available in one file. The solution is to add the keyword extern to both the declaration and definition of the const variable.
Static static member
Static data members are defined or described with the keyword static.
Static member initialization is different from normal data member initialization. The format of static data member initialization is as follows:
At this point, the study of "A brief introduction to variables and pointers in C++" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.