C_ operator notes

1. assignment operator: 

= The value assigned to the variable on the left side of the right

 

2. Arithmetic operators:

+ The value of its left and right are added

- subtracting the value of the left side of the right value

- As a unary operator, the right to change its sign value

* The value of the value obtained by multiplying the left side of the right side

/ Left value is divided by the value of its right side, if the two numbers are integers, the calculation result is truncated

%, On the left when it is divided by the right, taking the remaining number (applies only to integers)

++ its value plus 1 (prefix pattern) right or left of its value plus 1 (suffix pattern)

- its right value minus 1 (Prefix Mode), or the value of its left minus 1 (suffix pattern)

 

Other operators:

sizeof obtain its right operand size (in bytes), the operational object may be a parenthesized type specifier, as sizeof (a float), or a specific variable names, array name and the like, the sizeof foo (type name) cast operator converts the value to the right of the type specified in parentheses, such as (a float) 9 9 converting integers to floating point 9.0

Increment (decrement)

(I) Classification

① Before increment - ++ i

Increment after ② - i ++

 

Similarities and differences with the increment after increment before (ii)

① the same point

Eventually make the value of i is incremented by 1

② different points

Increment before the expression is a value obtained by adding 1 i

Since the expression is increased value before adding 1 i (specifically see Tan C)

(Iii) increase the role of self

 

① code more refined

② from growing faster

 

(Iv) learn a few questions to understand the increment

① we should try to shield the difference before and after the increment away from the growing programming (to increase readability)

② ++ i or i ++ do a separate statement, not to him as part of a complete compound statement

Counterexample:

⑴int m=i++ + ++i + i +​ ++i

​⑵printf("%d %d %d",i++,++i,i)

Both versions are not standardized, low readability and portability

 

Ternary operator

(I) format:

A?B:C

"And:?" Collectively known as ternary operator

(Ii) function:

Equivalent to

  if(A)​

       B;

  else

       C;

(Iii) Examples

#include<stdio.h>

 

int main(void)

{

   int i;

   i=(5>3?4:3)

   printf("%d",i);

   return 0;

}

Output: 4

(Iv) Note

Ternary operator is not commonly used, because he was not clear if function structure, but less code

 

Comma expression

(I) format

(A,B,C,D)

(Ii) function

From left to right ABCD  

The final value of the expression is the value of the last item

(Iii) Examples

  int i=(1,2,3,4)

  printf("%d")

Guess you like

Origin www.cnblogs.com/qinenxi/p/11111860.html