C language study notes 3

C language operators:

Arithmetic Operators

Assignment Operators

Relational Operators

Logical Operators

Ternary operator

Arithmetic operators:

Divide operation Note: If the division of two numbers are integers , then the result is also an integer , fractional part omitted, such as 8/3 = 2; and the two numbers have a decimal , the result was decimals , such as: 9.0 / 2 = 4.500000.

Remainder calculation Note: this operation is only suitable for two integers performed modulo operation, such as: 3 = 10% 1; 3 and 10.0% is wrong; symbols depending on the sign of the arithmetic modulus, such as ( -10)% 3 = 1; in 10% (- 3) = 1.

Note: C language is not the exponentiation operator, nor can ×, ÷ arithmetic signs and the like.

Increment decrement operator: increment operator is "+", which is a function of the variable value is incremented by one; decrement operator is "-", whose function is to subtract 1 from the value of the variable. They are often used in a loop.

Note: Whether a ++ or ++ a are equivalent to a = a + 1, the value of a finished after expression are incremented by 1, regardless of a-- or --a are equivalent to a = a-1 , after the value of a finished expression are reduced from 1.

Note: increment operator (+) and decrement operator (-) can only be used for variable or constant and can not be used for expression. Like 5++or (a+b)++they are not legitimate. Because 5 is a constant, constant value can not be changed. (a+b)++It is impossible to achieve.

Assignment operator (including the simple assignment operator and the compound assignment operators):

Example: integer variable is defined and assigned to a. 3, a + = 5; this formula is equivalent to a = a + 5; then assigned to a variable a and 5 after the addition.

Note: space does not exist between the composite operators and operators in the equal sign.

Relational operators:

Relational expressions is "true" and "false", represented by integers 1 and 0 in the C program.

Note:> =, <=, ==, = space between such symbols can not exist!.

Logical Operators:

Value of the logic operation are also two "true" and "false", C language using integer 0 and 1 are represented.

Evaluation rules as follows:

1) and operation (&&): involved in computing two variables are true , the result was true , and false otherwise.

2) OR operation (||): two variables involved in the operation as long as one is true , the result will be true . Two quantities are false, the result is false.

3) non-operation ():! Variables involved in computing is true , the result is false ; involved in computing the amount of time is false , the result is true .

Ternary operator: C language ternary operator: "?:"

The format is: Expression 1 Expression 2:? Expression 3; 

First determine whether the value of the expression 1 is true, if it is true, then executing the expression 2; if it is false, then the expression is executed 3.

Operators Competition compare the priority: Priority is the order of operations in the calculation.

Priority 1 is the highest priority, the priority level is the lowest priority 10.

Example: If the data type int and float or double data type operation, first type int and float type data into double-data, and then calculates, as a result of double type.

Cast:

Its role is the calculation result of the expression cast to type descriptions Type symbol represents.

Note the following issues when using cast:

1, data type and the expression must be in parentheses .

2、转换后不会改变原数据的类型及变量值,只在本次运算中临时性转换

3、强制转换后的运算结果不遵循四舍五入原则

printf 和 scanf 中的格式字符:

在输入函数时,用 %c 格式声明输入字符时,空格字符和转义字符都是作为有效字符输入。

在使用 %d 输出时,我们可以指定输出的宽度。

具体用法:

%d:按照整型数据的实际长度输出。

%md:以m指定的字段宽度输出,右对齐。

%ld:输出长整型数据。

%mld:输出指定宽度的长整型数据。

putchar 函数输出一个字符:一般形式:putchar(c); 功能:输出变量 c 所代表的一个字符; 说明:c 为字符型变量或整型变量。

getchar 函数输入一个字符:一般形式:getchar(); 功能:要求用户从终端(键盘)输入单个字符; 说明:返回值为从输入设备上得到的字符。

 

Guess you like

Origin www.cnblogs.com/www-bokeyuan-com/p/11145109.html