C-02 basic operations, C-02 Operations
1. division operation/
An integer is an integer except an integer. The operands involved in the operation must be of the same type.
1/2 is 0. The type of the operands involved in the operation and the obtained value. 10.5 + 10: Increase the value of 10 on the right to the double type.
Int B = 10.5 + 1.7; automatic conversion of large types to small types will result in loss of precision.
Double a = (double) 1/2; note: all involved in the operation are integer, so please turn it over.
2. remainder operation % (modulo operation)
% The two sides can only be integers.
Positive and negative are determined by the value on the left of %.
# Include <stdio. h> int main () {int input; int minute; int second; printf ("enter a time value (seconds): \ n"); scanf ("% d ", & input); minute = input/60; second = input % 60; printf ("You entered: % d seconds \ n", minute, second ); return 0 ;}
3. Auto-increment/auto-Increment
Int a = 10; int B; B = a ++ a // note that 22 10 + + is the 10 = 10 + 1 constant of the error.
4. view the number of bytes in the memory.
Int size = sizeof 10; // 4int size = sizeof 10.9; // 8int a; int size = sizeof a; // 4 // sizeof (constant/variable) int size = sizeof (int) can be omitted; // 4 sizeof (data type) cannot save brackets
5. Relational operators
The C language specifies that all values are false. Any non-0 values are true, and only 0 values are false ". That is to say, 108,-18, 4.5, and-10.5 are all "true", while 0 is "false ".
There are only two types of Relational operators: if the condition is true, the result is 1, that is, "True". If the condition is not true, the result is 0, that is, "false"
# Include <stdio. h> int main () {int a = 3; int B = 7; int result = B>; // result is returned as 1 printf ("result = % d \ n", result); return 0 ;}
=,! In Relational operators ,! = Has the same priority. <, <=,>,> = has the same priority, and the former has a lower priority than the latter: 2 = 3> 1
The Union direction of Relational operators is "from left to right": 4> 3> 2
The priority of Relational operators is less than that of arithmetic operators: 3 + 4> 8-2