4. C Language Learning ---- operators and expressions in C Language

Source: Internet
Author: User
Tags bitwise operators

Operators and expressions in C Language


Operators and expressions

Operators in C language, also known as operators, are symbols used to perform operations between data. Operators in C language can be divided into value assignment operators, Arithmetic Operators, logical operators, Relational operators, bitwise operators, pointer operators, and member operators by operation type. operators by operation objects (also called operands) the number can be divided into the single object operator, binary operator, and three object operator.

Concatenates data or variables with operators to form a c expression. An expression is a meaningful expression that concatenates an object with an operator according to certain rules. The calculation object in an expression can be a constant, variable, function, or another expression.

Arithmetic Operations, value assignment operations, and type conversion


Arithmetic Operators and arithmetic expressions

The arithmetic operators in C language include five binary operators: plus "+", minus "−", multiplication" * ", Division"/", and remainder (Modulo) "%" and four single-object operators: auto-increment "++", auto-increment "−", single-object addition "+", and single-object subtraction (arithmetic inversion) "− ", in addition, there are Parentheses "()" operators that can be used to change the order of operations.

The auto-increment "++" is divided into the front ++ and the back ++ plus the front ++, that is, adding 1 first and then adding 1 with the original value;

The auto-increment "--" is divided into the front -- and the back -- the front -- is to first subtract 1 and then use the original value and then minus 1;

An expression composed of Arithmetic Operators, values, variables, and so on is called an arithmetic expression.

Value assignment operator and value assignment expression

The value assignment operation is used to change the value of a variable. The C language provides a simple assignment operator "=" and 10 composite assignment operators: + =, −=, * =,/=, % =, <=, >=, & =, ^ =, and | =.


Type conversion Operator

In expressions, when different types of data are mixed, the C language will automatically convert their types. This conversion is generally "up, that is, the data type that occupies a small bucket is converted to the data type that occupies a large bucket.

Logical operators and expressions

Logical operations are completed by logical operators. There are three logical operators:

& Logic and

| Logical or

! Non-logical

The logic operation rules are as follows:

A & B/* The operation result is true (1) only when the values of A and B are true. Otherwise, the operation result is false (0 )*/

A | B/* The calculation result is false (0) only when the values of A and B are false. Otherwise, the result is true (1 )*/

! A/* When A is true, the result is false (0). When a is false, the result is true (1 )*/

When compared with other types of operators that have previously been learned, it has the following relationships:

Non-logical! > Arithmetic Operators> Relational operators> logic and &> logic or |> value assignment operators


Conditional operation

Conditional operators are the only three-object operators and the most special operators in C language.

The format of conditional operators is as follows:

Expression 1? Expression 2: expression 3

It means that if expression 1 (condition) returns true, the result of the entire operation is the value of expression 2; if expression 1 (condition) returns false, the result of the entire operation is the value of expression 2.


Sizeof Operator

The sizeof operator is used to calculate the size of its operands, that is, the number of nodes occupied by it in memory.


 

 

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.