1, Executive summary
1. Error prone operator;
2, Detailed content
1. Error prone operator:
○ 1 + +, -, pay attention to distinguish between front and rear.
int i = 10; int j = ++i;//i is 11 and j is 11 i = 10; int k = i++;//i is 11 and k is 10
○ 2 /, pay attention to the division problem, that is, the result of dividing an integer by an integer is an integer, and the decimal at the end is discarded; Cannot divide by 0.
○ 3 < <, move to the left according to the position, and supplement 0 uniformly on the right.
○ 4 > > shift right by bit. If it is a signed number, fill the sign bit on the left, and if it is an unsigned number, fill 0 on the left.
○ 5 <, > less than, greater than symbol, note that continuous comparison is not allowed
int a = 10; int b = 5; if(a>b>2)//Output "false" { printf("really\n"); } else { printf("false\n"); }
○ 6 write the equal sign "= =" incorrectly as the assignment symbol "="
int a = 10; if(a = 100)//The output "true" and "= =" are false. It is recommended to write it as if(100 == a) { printf("really\n"); } else { printf("false\n"); }
○ 7 "^" in C language is a bitwise XOR. Do not mistake it for the mathematical "index" symbol.
int a = 10^3;//The result is 9, not 1000
Operator:
Bool: true, false C99
Logical predicate:! (non), & & (and), | (or)
True: not 0
False: 0
Expression 1 & & expression 2: only when expression 1 is true and expression 2 is true can it be true (only when both are true can it be true)
Expression 1 | expression 2: if expression 1 is true or expression 2 is true, it is true (as long as one is true)
&& And |: short circuit phenomenon (in & &, if expression 1 is false, expression 2 will not be calculated; in |, if expression 1 is true, expression 2 will not be calculated)
Bit operator: for binary (assuming that the following number is 1 byte), 1 byte = 8 bits
Decimal to binary: a method of rounding up one hundred and twenty-eight sixty-four 32 16 8 4 2 1
80 to binary: 0101 0000
100 to binary: 0110 0100
12:0000 1100
13:0000 1101
~ 12: 1111 0011 bit inversion
13 & 12:0000 1100 by bit and the same bit is 1
13 | 12:0000 1101 by bit or, if one of the same bits is 1, it is 1
13 ^ 12:0000 0001 by bit XOR, the same bit is different, which is 1. Pay attention to the exponential distinction between mathematics and mathematics
13 < < 1:000 11010 26 = 13 * 2 move left according to the position, and supplement 0 uniformly on the right
13<<2:00 110100 52=13*4
13> > 1:00000 110 6 = 13 / 2 shift right by bit and fill the sign bit on the left
/: Division, integer division: divide an integer by an integer, and the result is also an integer (discard decimals). Use more and test more
%: remainder: get the remainder after division. It can be used to judge whether to divide
=: assign the value on the right to the value on the left
==: equal sign
!=: Unequal sign
3*4:
>: error prone and cannot be compared continuously
Expression 1? Expression 2: expression 3 If expression 1 is true, expression 2 is executed, and if expression 1 is false, expression 2 is executed
#include <stdio.h> //Find the maximum of two numbers int main() { int a; int b; scanf_s("%d%d",&a,&b); int c = a > b ? a : b; /* int c; if (a > b) { c = a; } else { c = b; }*/ printf("Maximum=%d\n",c); return 0; } /* int main() { int a = 10; // if (0 < a < 5)//error if(0<a && a<5) { printf("True \ n ""); } else { printf("False \ n ""); } return 0; } */ /* int main() { int n; scanf_s("%d", &n);//Get an integer value from the keyboard // printf("%d\n",n); //Judge whether this n is a leap year if (n % 4 == 0 && n % 100 != 0 || n % 400 == 0) { printf("%d Is a leap year \ n",n); } else { printf("%d Not a leap year \ n",n); } return 0; } */ /* int main() { // printf("%d\n",5/2);//%d:Output decimal integer //printf("%d\n",-9/0);//error //printf("%d\n", -9 / 2); printf("%d\n",5%2);//1 5/2 = 2 ... 1 printf("%d\n", -5 % 2);//-1 -5/2 = -2 -1 printf("%d\n", 5 % -2);//1 printf("%d\n", -5 % -2);//-1 return 0; } */ /* int main() { int a = 0; int b = 0; int c = 0; if (++a && b++ && ++c)//Short circuit phenomenon { printf("True \ n ""); } else { printf("False \ n ""); } printf("%d,%d,%d\n",a,b,c); return 0; } */ /* int main() { int i = 10; //int j = ++i;//Front++ //int j = --i;//Front-- // int j = i++;//Post++ int j = i--; printf("%d,%d\n",i,j); return 0; } */ /* int main() { // if (!10) //if(5>3 && 5<4) if(5>3 || 5<4) { printf("True \ n ""); } else { printf("False \ n ""); } return 0; } */ /* //True and false value int main() { //if (1)//If //if(2)//really //if(0.5)//really // if("Hello ") / / really if(0)//false { printf("True \ n ""); } else//otherwise { printf("False \ n ""); } //printf("Welcome to study graph theory \ n ""); return 0; } */