In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "C++ program expression analysis". In daily operation, I believe many people have doubts about C++ program expression analysis. 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 "C++ Program expression Analysis". Next, please follow the editor to study!
In C++, all the code is composed of identifiers (Identifier), expressions (Expression), statements (Statement) and some necessary symbols (such as curly braces, etc.).
Identifier
An identifier is a sequence of letters, consisting of uppercase and lowercase letters, underscores and numbers, used to identify. The logo is to mark and identify, that is, the name. It can be used as the name of the variable or function or class that will be mentioned later, that is, it can be used to identify a specific variable or function or class and other elements in C++.
For example: abc is a legal identifier, that is, abc can be used as the name of variables, functions and other elements, but does not mean that abc is the name of a variable or function, and the so-called legal is that any identifier must not start with a number, can only include uppercase and lowercase letters, underscores and numbers, can not have other symbols, such as,! ^, and can not be the same as C++ keywords. That is, when we name a variable or function, we must regard the name as an identifier, which in turn must meet the requirements mentioned above. For example, 12ab_C is not a legal identifier, so we cannot give a variable or function a name like 12ab_C; ab_12C is a legal identifier, so it can be used as the name of a variable or function.
Mentioned above, in the following statements and some declaration modifiers, C++ provides some special identifiers as the names of statements to identify a specific statement, such as if, while, etc., or some modifiers to modify variables, functions, and other elements to achieve semantics or to provide compilers and connectors with some specific information for optimization, error checking and other operations, such as extern, static, etc. Therefore, when naming variables or functions or other elements, you can not use C++ keywords such as if, extern as names, otherwise the compiler will not be able to confirm whether it is a variable (or function or other C++ element) or a statement, and then cannot compile.
If you want an identifier to be the name of a particular variable or function or class, you need to use a declaration, which will be specified in a later article.
Figures
C++ as a computer programming language, computers process numbers, so the basic thing in C++ is numbers. C++ provides two kinds of numbers: integer and floating point, that is, integers and decimals. However, because the computer is actually not as digital as imagined (see the types section in C++ from scratch (3) for details), integer numbers are divided into signed and unsigned integers, while floating-point numbers are divided into single-precision and double-precision floating-point numbers, and the same integers are also divided into growth integers and short integers according to length.
To represent a number in C++ code, write a number directly, such as 123,34.23,34.34, etc. Because the computer is not based on numbers and leads to the classification of the previous numbers, in order to show it in the code, C++ provides a series of suffixes for representation, as follows:
U or U indicates that the number is an unsigned integer, such as 123u, but it does not mean that it is a long integer or a short integer.
L or L means that the number is a long integer, such as 1231; 123ul is an unsigned long integer; and 34.4l is a long double-precision floating-point number, which is equivalent to a double-precision floating-point number.
I64 or i64 indicates that the number is a long integer, which is defined for the 64-bit operating system and is longer than the long integer. Such as: 43i64
F or F indicates that the number is a single-precision floating-point number, such as 12.3f
E or E represents the power of a number, for example: 34.4e-2 is 0.344 + 0.2544e3f represents a single-precision floating-point number with a value of 254.4
When no suffix is written, the specific type is determined according to whether there is a decimal point and the number of digits. For example, 12341434 represents a signed integer, while 34.43 represents a signed long integer, and 34.43 represents a double-precision floating point number.
Why do we have to do so many things, why are there any signs or no symbols? This is all because computers are not number-based, but status-based, details of which are described in more detail in the next section.
As a scientific calculation, you may often come across the use of non-decimal numbers, such as hexadecimal, octal, etc. C++ also provides some prefixes to support this.
Adding 0x or 0X before the number indicates that the number is represented in hexadecimal, such as 0xF3Fa, 0x11cF. Adding a 0 in front indicates that the number is represented in octal, such as 0347, which becomes a decimal number. But neither hexadecimal nor octal can be used to represent floating-point numbers, only integers, that is, 0x34.343 is wrong.
String
C++ provides characters and strings in addition to the most basic representation of numbers. This is provided entirely out of convenience for programming. As a computer language, C++ has no need to provide strings at all. However, because the basic requirement of the computer is to display the results, and characters and strings are used to display the results because they are human-readable symbols, C++ provides special support for strings.
As mentioned earlier, computers only know numbers, and characters are text symbols, a kind of graphic symbols. In order for a computer to process symbols, it is necessary to turn symbols into numbers in some way, which is achieved by establishing a mapping between symbols and numbers, that is, a table. The table has two columns, one column is the graphical symbol we want to display, and the other column is a number, through such a table, we can establish a mapping between graphical symbols and numbers. A standard table, called the ASCII code table, has been defined, and almost all computer hardware supports this conversion table to turn numbers into symbols to display the results of calculations.
With the above table, when you want to show that the result is "A", look up the ASCII code table and get that the number corresponding to the graphic symbol "A" is 65, then tell the computer to output the character with serial number 65, and finally display "A" on the screen.
This is obviously so cumbersome that C++ provides characters and strings. When we want to get the serial number of the ASCII code table of a graphical symbol, we only need to enclose that character in single quotation marks, such as:'A', the effect is the same as 65. When you want to use more than one character, enclose multiple characters in double quotation marks, which is the so-called string, such as "ABC". So a string is just a combination of characters. However, according to the previous instructions, it is easy to find that strings also need to be mapped to numbers, but its mapping is not as simple as characters that can be done by looking up the table, which will be explained after the array is introduced in subsequent articles.
Operator
The basic part of the computer is numbers, so all the operations of the computer are to change numbers, so C++ normally provides some basic operations for manipulating numbers, called Operator, such as +-* / and so on. Any operator returns a number called the return value of the operator, so the operator is the symbol that manipulates the number and returns it. As a general classification, it is divided into unary, binary and ternary operators according to the number of numbers in which the operators act at the same time.
The unary operators are:
+
The number is followed by the number, and the following number is returned intact. For example, the return value of + 4.4f is 4.4%. The return value of color 9.3f is-9.3. It is entirely out of semantic needs, such as indicating that this number is positive.
-
It is followed by a number, and the symbol of the following number is reversed. For example, the return value of-34.4f is-34.4f-(- 54) is 54. Used to represent a negative number.
!
The number is followed by the number, and the logic takes the following number in reverse. Logical values are "true" or "false". In order to represent logical values with numbers, it is stipulated in C++ that a non-zero value is logically true and zero is logically false. So 3, 43.4, and'A 'all indicate logical truth, while 0 indicates logical false. Logical values are applied to subsequent judgments and loop statements. And logical reversal is to judge "!" Whether the following number is logically true or false, and then invert the corresponding value. For example, the return value of! 5 is 0, because it is known to be logically true by the fact that 5 is not zero, and then logical false is obtained, so 0 is returned finally. The return value of 345.4 is 1, because 345.4 is not zero to get logical truth, then take the reverse to get logical false, and then take back to get logical truth. Although as long as non-zero is logical truth, as the logical truth returned by the compiler, it always uses 1 to represent logical truth.
~
It is followed by a number, and the number followed by it is reversed. Inversion is an operation defined in logic and cannot be applied to numbers. In order to apply inverse operations to numbers, the number is represented in binary in the computer, and then every bit of the number is inverted (because each bit of the binary number can only be 1 or 0, which coincides with the logical true and false). For example, the return value of ~ 123 is-124. First convert 123to the binary number 01111011, then you get 10000100, and finally-124. The question here is why it is 8-bit instead of 16-bit binary numbers. Because 123is less than 128, it is positioned as a char type, so it is 8-bit (the next article describes what char is). If it is ~ 123ul, the return value is 4294967172. Why should there be a number to reverse this operation? Because CPU provides such instructions. And it also has very good and very important applications, which will be introduced later.
Other unary operators will be mentioned in subsequent articles (but not all of them).
The binary operators are:
+-* /%
It is followed by a number before and after each, and returns the sum, difference, product, quotient and remainder of the two numbers. For example, the return value of 34 minutes 4.4f is 38.4 percent, and the return value of 3percent music 9.3f is-6.3. The return value of 34-4 is 30. The return value of 5-234 is-229. The return value of 3room2 is 6. The return value of 3 is 3. The return value of 10% 3 is 1% 20% 7 and the return value is 6.
& & | |
It is followed by a logical value before and after each, and returns the "and" operational logical value sum "OR" operational logical value of the two logical values. For example, the return value of 34.3f is logically true, and the return value of 34.3f is logically false, which is 0. 0 | | the return value of'B' is logically true and 1 is true | | the return value of 0 is logically false and 0.
& | ^
It is followed by a number before and after each number, and returns the "and" operation, "OR" operation, "XOR" operation value of the two numbers. As mentioned earlier, convert the numbers on both sides to binary numbers, and then and, OR, XOR. For example, the return value of 414 is changed from 4 to 00000110, and the return value is 00000100, which is 4. | 4 | the return value of 6 is 6, which is changed from 6 to 00000100, and 6 is converted to 00000110, and 00000110 is 6. | The return value of 4 ^ 6 is from 2meme 4 to 00000100jue 6 to 00000110 different or, 00000010, to 2.
The return value of > = 34 is 0, which is logically false; the return value of 32 > 23 and 23 > = 14 is 1, which is logically true; 54 > 2 is equivalent to the quotient of 4max 4; 32 > > 3 is equivalent to 32 amp 8, that is, the quotient of 32 divided by 2 to the third power. And 4435 is there? This is the meaning of the expression.
There is a number before and after the ">", but the operator is a symbol that manipulates the number and returns the number, because it returns the number, so it can be placed anywhere above that requires a number, which forms the so-called expression. For example, the return value of 23x54 stroke 45 > 34 is 0, because the return value of 2354 is 1242; then it takes 1242 as the left numeral of "/" and gets the new return value of 27.6; finally, it takes 27.6 as the left numeral of ">" and gets the return value 0, which is logically false.
So an expression is a piece of code made up of a series of things and operators that return a number, and because it is made up of operators, it must return a value. The previously mentioned "something that returns a number" can be another expression, or a variable, or a function with a return value, or an object of a class with a numeric type operator overloaded, etc., anyway, as long as it is something that can return a number. If you are unfamiliar with what are variables, functions, classes and other nouns, you don't need to worry about them, which will be explained in the following articles.
So 34 is also an expression with a return value of 34, just an expression without an operator (you'll see later that 34 is actually an operator). Therefore, the concept of expression is actually very broad, as long as there is a return value of something can be called an expression.
Because there are many operators in the expression, the order in which the operators are executed depends on the priority of the operators, just as in mathematics, the priority of * and / is greater than +, -, and +,-is greater than >,
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.