c Notes Summary


C relive some of the video, recording some notes


 

C strings are in double quotes " ..." enclosed sequence of characters : "ABC" , "123456"

printf ( " print strings % s \ n", "abc / 123456");

printf( “%d\n” , 1 + 1 );

 

Data types and variables:

Integer types: Type without a decimal point, % D

Float Type: type with decimal point, % F

Character types: English character type, character data using a single quote character enclosed 'a', 'n', '\ n' ( is not the echo character ),% c

 

Changing the operation of the variable value is called the assignment operation represented;

  =   Is the assignment symbol in the program;

After defining the variables represented by the assignment change;

 

Initialize a variable that is created out of make variable has an initial value;

While giving a definition of a variable value;

 


 

Four operations: +, -, *, /,% ( Remainder calculation, the result is the number of I, I can not take floating point arithmetic ) , then the first sign of multiplication and division most after subtraction;

Relational operators: <,>, <=,> =, ==,! = Result is a logical value: true (1) , False (0) , the size of the comparison operation > equal comparison operation;

Logic operations: &&, ||,! Logical operation is a logical value of participants: true or false, any nonzero value in the logic operation are true, any zero values are false in the logical operation;

 

Short-circuit the logic operation rules:

For && , from left to right, if either operand is false, the entire expression is false, the first operation after a number of false other operand is not evaluated;

For || , performed from left to right, if either operand is true, then the whole expression is true, a true first operation after the number of the other operand is not evaluated;

Negated by, unary, only one operand, the result of arithmetic logic value, true value negated false false true value is negated;

c = !! c; // non 0 i.e. 1

 

Bit operation: |, ^, &, >>, <<, ~ only integer operations on operands, the priority from low to high;

~   Bitwise, ~ 0101 = 1010

<< left, out of high, low fill 0 , 0011 << 1 = 0110

>> right, removing the low, the high bit of the sign bit, 0101 2 = 0001 >>

&   Bitwise AND, 0011 & 1111 = 0011 , and a bit 0 and, and the remaining 1 and, according to the position corresponding to zero

^   Bitwise exclusive-or, the same as 0 , it is different from 1 , not to carry adder, 0011 ^ 1111 = 1100 , and a bit 1 XOR corresponds to negated

|   Bitwise OR, 0011 | 1111 = 1111 , and a bit 1 bit or equivalent to set 1,

 

Priority : four operations > relational operators > assignment operator ( = )

Expression should be avoided with a different type of operation (arithmetic, relational operators)

 

Original code is represented by a positive number, negative numbers complement representation

 

When the first clear bit operation:

1 type of operand, memory size;

2 operand is positive or negative;

3 operands different types of first bit operation then automatically aligned; (complement sign bit)

 


 

Left and right values,

Left value: the value of the assignment symbol can appear in the left side, such as variable

Right value: value that appears in the right of assignments, such as variables, literals, the calculation result ( A + B ), any expression

 

Continuous variables are defined and continuous assignments

Int a , b , c ;  a = b = c ;   →   b = c ; a = b ;

 

Ternary operator (conditional operator)

( Condition ?) ( Is true statement ): ( is false statement )

 ? (b <10) (a = 10): (a = 100); ternary operator generated is a value, the value can not be used as a left;

 

Comma expression, can be connected to a plurality of statements a statement, the statement is executed from left to right, the value of the expression is a value comma rightmost statement; C = (A = 2, B =. 3, A + B); → c = 5;

 

Increment decrement operator ++ - -

Front: first increment decrement, then the value

++ v → (v = v + 1, v)

 --v → (v = v-1, v)

Rear: the first value, and then increment-decrement

v ++ → (v = v + 1, v-1)

v-- → (v = v-1, v + 1)

 

Increment decrement operator binding direction: from right to left, int. 1 = C; A = -C ++;   A = -1; C = 2;

Increment decrement does not support floating-point type

 

char byte; Short two bytes; int four bytes;

 

The most significant bit is a positive number of 0 , the most significant bit is negative 1;

Complement positive number itself is positive, negative to negative complement negated absolute value plus 1;

 

Unsigned default is positive, unsigned without a sign: unsigned

 

Signed -10 and unsigned 5 number is bigger than the sum 0 , because the symbols are converted to unsigned;

▲ for variable decrement the loop i can not be set unsigned, otherwise an infinite loop

 


 

Type of conversion

char->short->int->unsigned int->long->unsigned long->float->double

 

for cycle before entering the loop judgment, suitable for the case where a fixed number of cycles

while loop determines Advanced loop reentry, used in the case where the number of cycles is not fixed

do ... while loop then the first iteration of the loop condition judgment cycle at least once loop

 

while ((scanf ( "% d ,% d", & a, & b)) == 2) {scanf returns the number of successful data reading, if not two numbers will result in a positive cycle terminates }

 

scanf ( "% * s") ; skip to the next blank character, the error value in a buffer of non-return required for processing;

 

% p is the output of the address conversion described: the printf ( "% P", P);

 

Guess you like

Origin www.cnblogs.com/ren-hang/p/12644032.html