An
Arithmetic expression
is a formula that is connected by an arithmetic operator and parentheses, and the following are examples of arithmetic expressions:
A+b (a*2)/C (x+r) *8-(a+b)/7 ++i sin (x) +sin (y) (++i)-(j + + k--)
Assignment operators and Assignment expressions
Simple assignment operators and expressions, the simple assignment operator is recorded as "=". An expression that is connected by an "=" is called an assignment. The general form is: variable = expression For example:
X=a+b
W=sin (a) +sin (b)
The function of an y=i+++--j assignment expression is to evaluate the value of an expression and then give the variable to the left. The assignment operator has a right binding. So
A=b=c=5
Can be understood as
A= (b= (c=5))
In other high-level languages, the assignment constitutes a statement, called an assignment statement. In C, the "=" is defined as an operator, thus constituting an assignment expression. An assignment expression can occur wherever an expression appears. For example, the formula x= (a=5) + (b=8) is legal. Its meaning is to give a,8 5 to give B, then add A,b, and give x, so x should equal 13.
The C language can also be composed of assignment statements, in accordance with the C language, any expression in its end with a semicolon constitutes a statement. So, like X=8;a=b=c=5, it's all assignment statements, which we've used a lot in the previous examples.
If the data types on either side of the assignment operator are different, the system automatically converts the type to the right of the assignment with the type on the left. The specific provisions are as follows:
1. The real type assigns integral type, gives out the fractional part. This situation is illustrated in the previous example 2.9.
2. Integral type is given to the real type, the value is unchanged, but will be stored in floating-point form, that is to add fractional part (the value of the decimal part is 0).
3. Character type gives integral type, because character type is one byte, and integral type is two byte, so the ASCII code value of the character is placed in the lower eight digit of the integral type, high eight digit is 0.
4. The integral type gives the character type, and only the lower eight bits are assigned the character quantity.
void Main () {
int a,b=322;
float x,y=8.88;
Char c1= ' k ', C2;
A=y;
X=b;
A=C1;
C2=b;
printf ("%d,%f,%d,%c", A,X,A,C2);
}
int a,b=322;
float x,y=8.88;
Char c1= ' k ', C2;
printf ("%d,%f,%d,%c", a=y,x=b,a=c1,c2=b);
This example shows the rules for type conversions in the above assignment operation. A is an integral type, giving a real value of y 8