Data types, operators and expressions

Data is the object of program processing and processing, and it is also the result of program processing and processing.
Constants are also called constants, which are data whose values ​​cannot be changed during program operation.
Constants can have different types. C language stipulates constants including integer constants, real constants, character constants, string constants and symbolic constants.
When using constants, you don't need to define them in advance, you just need to write them out directly in the program. The type system of constants can be automatically identified through the written form, without definition.
Integer constants are usually called integers, without fractional parts, including positive integers, negative integers and 0.
Because integer constants are divided into basic integers, short integers and long integers, they are divided into octal, decimal, and hexadecimal. There are three writing forms, so pay attention to the distinction when using integer constants.
Real constants are also called floating-point constants or real numbers. Real constants only use decimal.
Character constants include ordinary character constants and escape character constants. Common character constants are single characters enclosed in a pair of single quotes, for example:'a','?' are common character constants. In addition, the C language also allows the use of
a special form of character constants, that is, the escape character starting with a backslash "\", which only represents a specific ASCII code character.
String constants, also known as "strings", are sequences of zero or more characters enclosed in double quotes. The number of characters in a string is called the length of the string. If the string length is 0, it is called an empty string.
Symbolic constants are another way of expressing constants. In order to clearly express the meaning of certain constants in the program, you can give the constant an easily recognizable name, and the name of the symbolic constant should conform to the naming rules for identifiers.
Symbolic constants must be defined before they are used. The format is as follows
#define Symbolic
constants Advantages of symbolic constants: 1. Improve the readability of the program, 2. Facilitate program modification. If a constant is used in multiple places in the program, when its value needs to be modified, the modification operation is very cumbersome, and even omission may occur.
If the program defines symbolic constants, you only need to modify it at the defined position, which is small in workload and not easy to make mistakes.

Integer variables
According to the number of bytes of memory occupied, there are four types of integer variables, namely:
1. Basic integer, the keyword is int
2. Short integer, the keyword is short[int]
3. Long integer , The keyword is long[int]
4. Unsigned integer type is divided into unsigned basic integer type, keyword unsigned[int], unsigned short integer unsigned[short] and unsigned long integer unsigned[long] Three kinds

Real variables
Real variables are divided into two types, namely
1. Single-precision real type, the keyword is float, generally occupies 4 bytes
2. Double-precision real type, the keyword is double generally occupies 8 bytes

Character variable The
keyword of the character variable is char, which stores the ASCII code value of the character, occupying 1 byte of memory

Operators and expressions
Operators are symbols for various operations, such as the commonly used +, -, *, / symbols, which are operators
Insert picture description here

Operators in C language must have operands. According to the number of operands involved in the operation, operators can be divided into unary operators, binocular operators, and ternary operators.
When multiple operators appear in the expression, the calculation of the expression will be calculated according to the following priority table.
Insert picture description here

Operators also have associativity. The so-called associativity means that when the operators on both sides of an operand have the same priority, whether the operand is combined with the operator on the left or with the operator on the right.
The joining direction from left to right is called left joining, and the joining direction from right to left is called right joining. Except for unary operators, assignment operators, and conditional operators that are right associative, all other operators are left associative.

Relational operators include >,>=,<,<=,==,!= six kinds, they are all binocular operators.
Logical operators include &&, || and! Are used to perform operations on relational expressions and logical values, and the result of the operation is a logical value
. The priority of logical operators is as follows
:! Take precedence over binocular operators, take precedence over relational operators, take precedence over && over ||
unary operators! The precedence is the same as the binocular operator, and the associativity of the
binocular operator "&&" and "||" is from left to right.

An expression in which a variable and an expression are linked by an assignment operator or a compound assignment operator is called an assignment expression.
The comma operator is also called the sequential evaluation operator. It is a binocular operator. The operand is an expression and is often used in loop statements. The priority of the comma operator is the lowest, and the associativity is from left to right.
After-class exercise
1. Set int a=0, b=0, m=0, n=0, execute the statement (m=ab)||(n=avalue b) for m and n are 0 Solution: || front brackets to the operator a == b, m is assigned to true, then m = 1, corresponding to the value of m in brackets behind
true, so No calculation
2. Set int a; then the expression (a=2,3), the value of a+1 is 3, solution: a=2, a+1=3
3. Set int x=100; then the expression x++ >100? x+20: The value of x+10 is 111. The value of
x++>100 (100>100) is false, so x+10 is executed, but after x++ is executed, x=101, so 101+10 = 111
4. Set int a=11, the value of the expression a+=a-=a a is -220
solution: calculate from right to left a=a+a=aa
a; a=11-121, a=-110±110
5 .Set char c='A';int i =1,j; after executing the statement j=!c&&i++;, the values ​​of i and j are 1, 0
solution: c='A', !c=0; so i++ Do not execute j=0, i=1
6. The data type that cannot perform ++ and-operations is double 7. The operators of the C
language can be divided into monocular, binocular and ternary operators according to the number of operands.
8 The statement of precedence of operators in the C language is that arithmetic operators are higher than relational operators, and relational operators are higher than logical operators.

Guess you like

Origin blog.csdn.net/G_whang/article/details/113082612