iOS Development Learning Record the 5th day of C language learning

Source: Internet
Author: User
Tags arithmetic operators bitwise operators logical operators

(a),

(1), the concept and classification of operators

    An operator is a symbol that tells the compiler to perform a specific arithmetic or logical operation.

by function: arithmetic operators, relational operators and logical operators, bitwise operators.

Operators are based on the number of operands that participate in the operation:

Monocular operator, binocular operation, trinocular operation

Monocular operation: Only one operand such as: i++! sizeof

Binocular operation: There are two operands such as: a+b;

Trinocular Budget: The only one of the C language, also called the question mark expression a > B? 1:0//Determine if A is greater than B if yes, the value is

is 1, or 0.

       

Precedence and binding of operators:

There are two kinds of combinations of operators in C, that is, left-associative (left-to-right) and right-associative (from right to left). such as arithmetic operators

The binding is from left to right, that is, first left and right. If there is an expression x-y+z, then we should first calculate the X-y value, and then calculate the value of +z.

The right binding, such as: Y=z, is the assignment operator that we often see.

Priority: In C language, the operation priority of operations is divided into 15 levels. Level 1 Highest, 15 lowest. In the expression, the higher priority of the lower priority

To perform the operation. Operators on either side of an operand are treated in a binding direction as defined by the binding of the operator.

(2), the introduction and use of arithmetic operators

(3), the use of the remainder operator and matters needing attention

A%b For example: 10%3=1 here more than 1

Note: Both sides of the redundancy cannot be decimals

Positive or negative depends on the value of a, and B has no relation (A%B)

(4), type conversion problem in arithmetic operation

type conversions are divided into: implicit data type conversions and display data type conversions

For example: int a=10;   float f=3.1f;   int sum=a+b; So, like this, we call this implicit conversion, and the final result

to 13.1. Because it was the system that handled it for us.

For example: int a=10;   float f=3.2f int sum= (int) (A+F); Here we first calculate the value of a+f in parentheses.

then strong to int so the last The result is

(5), an expression, and an assignment operator

The meaningful expression of the same type of data (as usual, variable, function, etc.), which is connected by a certain rule by an operation symbol, is called an equation.

For example: arithmetic expressions, logical expressions, character expressions, and so on.

An expression can be a constant or a variable or a calculation, and in an expression it can be divided into: arithmetic expressions, logical expressions, and character-string expressions

Features of the expression:

An expression is a formula of meaning, so there must be a return value.

The assignment operator is recorded as "=" and the expression connected by "=" is called an assignment.

The function of an assignment expression is to evaluate the value of an expression and assign it to the left variable.

The assignment operator has a right binding, so a=b=c=5 can be understood as a= (b= (c=5)) by first assigning a value of 5 to the variable C, and then

Value Assignment of C

Give B, and finally assign the value of B to A;

Its general form is: variable = expression;

Classification of Expressions:

Arithmetic expressions, relational expressions, logical expressions

Expression statement: The expression is followed by a semicolon, which forms an expression statement.

(6), compound assignment operator

Precede the assignment "=" with the other two-mesh operators that make up the qualifier.

/= In addition to the post-assignment variable/= expression such as: A/3; A=A/3;

The *= expression of the *= after the multiplication is as follows: A*3; that is a=a*3;

%= the%= expression of the assignment variable after taking the modulus as follows: a%3; that is a=a%3;

+ = Plus post-assignment variable + = expression such as: a+3; i.e. a=a+3;

-= minus assignment variable-= expression such as: a-=3; i.e. a=a-3;

(7), self-increment self-decrement operator

The self-increment or decrement operation is a right-to-left combination of arithmetic operators, + + and--called the increment operator and the decrement operator, respectively.

For example: ++a,--A; (prefix expression), where a is the variable name, which represents the self-increment 1 operation of the completed variable, and then the value of a

as the value of an expression. that is, "change first, then use", that is, the value of the variable first change, and then use the value of the variable to participate in the operation.

For example: a++,a--; (suffix expression); The current value of a is used as the value of the expression, and then the self-increment-decrement 1 operation is performed. That is, "first use, then change"

i.e. variable values are first involved in the operation, and the value of the variable is then self-increment-decrement.

a++ or ++a are expressions, expressions have a return value

The value of an expression is not the same as the value of a variable

The value of the ++a or a++ expression is the value of the variable A.

(8), sizeof operator

(9), comma operator application and use note

(10), relational operator precedence and binding

(11), logical operator precedence and binding and short-circuit problems

(12), trinocular operator and its evaluation method

   

iOS Development Learning Record the 5th day of C language learning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.