Variables and constants are the two basic data Object declaration statements that the program handles to describe the name and type of the variable, or the initial value operator that specifies the action to be made, and the expression combines the variable with the constant to generate a new value all shaping includes signed and unsigned two forms
2.1 Variable Name
A variable name consists of a letter and a number, but its first character must be a letter. The underscore "_" is also considered to be a letter and is often used to name longer variable names because the name of the library routine usually begins with an underscore, so the variable name does not start with the underscore variable name using lowercase letters, Constant names all use uppercase letters
2.2 Data type and length
// The C language only provides the following basic data types Char character type, occupies one byte, can hold one character in the local character set int shaping, usually reflecting the most natural length of an integer in a machine float single-precision floating-point number Double double-precision floating-point number In addition, you can precede these basic data types with some qualifiers short with a long two qualifier to qualify the shaping: Short int sh; Long int counter keyword int can be omitted. The introduction of short and long can provide us with different lengths of shaping numbers that meet the actual needs signed and unsigned can be used to qualify char types or any shaping
2.3 Constants
An integer constant similar to 1234 is an int type long type constant with the letter L or L, such as 123456L if an integer is too large to be represented by an int, it will also be treated as a long process with an unsigned constant ending with the letter U or U. Suffix UL or UL indicates is unsigned a character constant is an integer that writes a word enclose characters in single quotation marks \a the bell character \b The fallback character \f the new page break \ n newline character \ r carriage return \ t transverse tab \v Portrait tab character constant ' / ' denotes a character with a value of 0, which is a null character (null) We usually The form of a 0 constant expression is simply an expression that contains only constants. This expression is evaluated at compile time, not at run time, the string constant is also called a string literal, and is a sequence of 0 or more characters enclosed in double quotation marks from a technical point of view, a string constant is an internal representation of a character array string using a single-person null character ' / ' as the end of the string
2.4 Statement
All variables must be declared after use, although some variables can be initialized by implicitly declaring variables in context if the variable is not an automatic variable, then only one initialization operation, conceptually, should be done before the program starts executing, And the initialized expression must be a constant expression each time the function or block is entered, the automatic variable that is explicitly initialized is initialized once. Any declaration of a variable can use the Const qualifier to qualify a const-qualified variable whose value cannot be modified, and the value of all elements of the const-qualified array cannot be modified in terms of arrays
2.5 Arithmetic operators
Binary arithmetic characters include: +-*/% . The modulo operator cannot be applied to a float or double type.
2.6 Relational operators and logical operators
relational operators include:> >= < <= They have the same priority = = = Priority Lower point logical operator && with | | There are some more special properties. by && | | concatenated expressions are evaluated from left to right, and stop the operation immediately after knowing that the result is true or false
2.7 Type Conversions
Automatic conversion refers to converting a " narrower " operand to a " relatively wide " operand . And does not lose the conversion of the information. When converting a character type to shaping, you need to be aware of a point where C does not specify whether a variable of type char is unsigned or signed. When converting a value of type char to an int type, is it possible that the result is a negative number ? Different results for different machines
2.8 Self-increment and self-reduction
The C language provides two operators for variable increment and decrement.
increment + + increments the operand by 1
Auto minus -- decrements the operand by 1
They can be used as either prefix operators or use suffix operators
2.9 Bitwise operators
the C language provides 6 bit manipulation operators. These operators can only be used for shaping operands. & Bitwise and | Bitwise or ^ bitwise XOR << shift left >> right ~ bitwise negation Bitwise AND operator & Often used to mask certain bits bitwise OR operators | often used to set some binary position to 1 bitwise XOR operator ^ when the corresponding bit of two operands is not the same as 1, otherwise set to 0 shift operator << with >> The number of digits that are used to move the left operand of an operation to the left and right moves is specified by the right operand. X<<2 means to shift x to the left 2 bits, 2 bits on the right to fill with 0 in the right shift of the unsigned value of the unsigned type, the left empty portion will be filled with 0 when the signed value of the signed type is shifted to the right, Some machines will fill the left empty portion with a sign bit, while others use 0 to fill the unary operator ~ for integer binary inverse code, that is, respectively, the operand of the binary 0 to change to 0
C Programming language Note (ii) Type operators and expressions