<< Dark Horse programmer >> Basic Arithmetic

Source: Internet
Author: User

The C language provides a total of 34 operators

Arithmetic operations

1 addition operation +.

2 addition operation-.

3 multiplication Operation X.

4 Division operation/.

5 residual operation%.

① the remainder after dividing two integers

②% can only be integers on both sides

③ positive and negative depending on% left value

Type conversions

Automatic type conversion

int a = 10.5;//will convert 10.5 to int type;

Forcing type conversions

int a = (int) 10.5; Now convert 10.5 to int type, assign a value to A;

Self-increment operation

+ + is a self-increment operator,

++a; indicates that the value of a is first used in addition one;

a++; means first to a plus one, in use a;

Use of sizeof

Used to calculate the number of bytes of memory occupied by a variable, a constant, and a data type;

Basic form

sizeof (variable/constant)

sizeof variable/constant

sizeof (data type)

sizeof data type This writing format is incorrect

Relational operations

>, >=, <, <=,! =;

The result of the relational operation is a total of two

① condition is established as true, the result is 1;

② condition is not established as false, the result is 0;

Note the point:

C language provisions, any value is true and false, not 0 of the value is true, only 0 is false;

Priority level

The precedence of = =,! = In the relational operator is equal;

The priority of <, <=, >, >= is equal, and the priority of the former is lower than the latter: 2==3>1

The associative direction of the relational operator is "left to right": 4>3>2

The precedence of the relational operator is less than the arithmetic operator: 3+4>8-2

Logic operations: &&, | | 、!

① conditions 1 && conditions 2

When condition 1 and condition 2 are true, the result is only 1;

When condition 1 is true, when condition 2 is false, the result is 0;

When the condition 1 is false, it is not necessary to judge whether the condition 2 is true or FALSE, the result is 0;

The combination of logic and direction is "from left to right";

② Condition 1 | | Condition 2

When condition 1 and condition 2 have only one to be true, the result is 1, which is true;

When condition 1 is true, it is not necessary to judge whether the condition 2 is true, and the result is 1;

When the condition 1 is false, judging whether the condition 2 is true, if the condition 2 is true, the result is 1, if the condition condition 2 is false, the result is 0;

The logical or binding direction is "from left to right".

③! Condition 1

If condition 1 is established, the result is 0;

If condition 1 is not established, the result is false;

Is true change false, false change true;

The logical non-union direction is "from right to left".

Trinocular operator

Conditions? Value 1: Value 2

int a = ten > 5? A:b

If the condition of > 5 is established and returns a, b if the condition is not established;

<< Dark Horse programmer >> Basic Arithmetic

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.