There are 34 types of operators in C, including common subtraction operations
1. Addition Operation +
Besides being able to do addition operations, it can also represent a plus sign: +5, +90
2. Subtraction operation-
Besides being able to do subtraction, it can also represent symbols:-10, 29
3. Multiplication Operation *
Note the symbol, not x, but *
4. Division Operations/
Note the symbol, not ÷, nor \, but /
An integer In addition to an integer or an integer. The value of 1/2 is 0, and this is not one-second.
5. Residual operation%
What is the remainder: two integers after dividing
% can only be integers on both sides
Positive and negative depending on% left value
6. Attention Points
1> Automatic type conversion
int a = 10.6;
int B = 10.5 + 1.7;
Automatic conversion of large type to small type, loss of precision
2> Automatic type Promotion
int B = 10.5 + 10;
Lift the 10 on the right to double type
Double b = 1.0/2;
Solve the problem of the precision of division
3> Coercion Type conversions
Double A = (double) 1/2;
Double b = (double) (1/2);
4> Order of Operations
An expression
Adhesion (combination direction): 2+3+4
Priority: 5+4*8-3
Precedence of operators (high-to-low)
Priority level |
Describe |
Operator |
1 |
Brackets |
()、[] |
2 |
PLUS sign |
+,- |
3 |
Self-increment, non- |
+ + 、--、! |
4 |
multiplication, taking surplus |
*、/、% |
5 |
Add and Subtract |
+,- |
6 |
Shift Operations |
<<, >>, >>> |
7 |
Size relationship |
>, >=, <, <= |
8 |
Equality relationship |
= =,! = |
9 |
Bitwise-AND |
& |
10 |
Bitwise XOR OR |
^ |
11 |
Bitwise OR |
| |
12 |
Logic and |
&& |
13 |
Logical OR |
|| |
14 |
Conditional operations |
?: |
15 |
Assignment operations |
=, + =,-=, *=,/=,%= |
16 |
Bit assignment operations |
&=, |=, <<=, >>=, >>>= |
If you want to change the order of operations in the program, you can use ().
7. Course Code
1#include <stdio.h>2 3 intMain ()4 {5 /*1. Basic use of arithmetic operators6 int a = ten + 1 + 2-3 + 5;7 8 int b = -10;9 Ten int c = ten * b; One A int d = 10/2; - - //Take-rest operation (modulo operation) the //% are integers on both sides - //% the positive and negative results of the residual result are only related to the value on the left of% - int e = ten%-3; - printf ("%d\n", e); + */ - + /* A //automatic type conversion (Double->int) at int a = 10.8; - - //coercion type conversion (Double->int) - int b = (int) 10.5; - printf ("%d\n", a); - */ in - //Automatic type lift (int->double) to Doublec =10.6+6; + - DoubleD =1/3; the * DoubleE = (Double)3/2; $ Panax Notoginsengprintf"The value of E is%f\n", e); - the + return 0; A}
1#include <stdio.h>2 /*3 prompt the user to enter a time of the number of seconds, such as 500 seconds to enter 500, and then output the corresponding minutes and seconds, such as 500s is 8分钟20秒4 */5 intMain ()6 {7 /*8 //The value of C is fixed to less than 109 int a = 96546546;Ten One int c = a%; A */ - - //1. Prompt user to enter time theprintf"Please enter a time value (seconds): \ n"); - - //2. Time to receive user input - intTime ; +scanf"%d", &Time ); - + //3. Convert to corresponding minutes and seconds A intminute = time/ -;//minutes at intSecond = time% -;//seconds - -printf"%d seconds =%d minutes%d seconds \ n", time, minute, second); - - return 0; -}
"Learning Notes", "C language" arithmetic operations