In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to analyze the important elements of C++ variables, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.
The C++ language also has an important variable: the pointer variable. The value it stores is a memory address. C++ variable names in C + language are case-sensitive, such as SUN and sun are two different variable names, so you can't confuse case, which will make the program very complicated.
1. The name of the variable
The name of a variable is an identifier, and the case of the name of the variable is different in the composition. Although C++ does not control the length of C++ variable names, it is restricted by the compilation system used. In general, variable names are in lowercase letters. Note that the variable names defined are not the same as keywords, library function names, class names, and object names.
2. Type of variable
Variables must be defined to indicate their data types before they can be used. Through type definition, variables are allocated a fixed storage space until the storage space is released at the end of the program. The operation of variables is controlled by type, for example, the operation of integer variables is different from that of floating-point variables.
3. The value of the variable
There are two values related to a variable: one is the data value represented by the C++ variable, and the other is the address value of the variable.
Among them, * * statements define a variable whose name is c and its type is character type. The second statement is to assign a value to the variable c so that the data value represented by the variable is'a value, which is the value stored in the memory address of the variable c.
In fact, the ASCII code value of the character an is stored in memory, which is expressed as an integer, so the integer data and character data in C++ can be assigned to each other, but we should pay attention to the reasonable range of their representation. For example, the following assignment is correct.
4. Definition and initialization of variables
Look at the following example:
# include void main () {int a; char ch; for (ch='a'; ch {aquarch; cout}})
Note: it is not allowed to define a variable with the same name in the same memory block, that is, it is not allowed to define a variable repeatedly. When a variable is defined, it can be given an initial value directly, which is called variable initialization. Variable initialization can also be done when needed. After the C++ variable is initialized, its value is saved until it is changed. After the C++ variable is defined, if it is not initialized, it does not mean that there is no value in the variable, either the default value or invalid value in the variable.
As we will see later, when external and static variables are defined, their default values are 0 for int, 0 for floating-point, and null for char. The value of other internal variables is invalid when they are not initialized, because the content in the address of the variable is a previously retained meaningless value.
When defining variables, you can initialize multiple C++ variables at a time. For example:
Float xrem yearly 3.14 jinn 0.0l; char ch2='a'; ch3='\ n'
Here, ymemezrech2rech3 is initialized while it is defined. And x just makes a variable to show that there is no initial value assigned.
After reading the above, do you have any further understanding of how to analyze the important elements of C++ variables? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.