Key Points of C language Review

Source: Internet
Author: User
Tags decimal to binary

C language most important knowledge point review material!

In general, it must be clear:
1) There are three program structures: sequential structure, cyclic structure (three cyclic structures), and select the structure (if and switch)
2) The read program should read from the main () entry and then from the top order (when a loop is encountered, the choice is selected ).
3) Computer Data is saved in binary format in the computer. The location where the data is stored is its address.
4) Bit indicates 0 or 1. Byte is a byte. one byte is eight digits.
5) Remember how to convert binary into decimal.
Concepts:
1. Compile and pre-process is not part of the C language and no longer run time. C language-compiled programs are called source programs, which are stored in text files with ASCII values.
2. There is only one main function in each C language program.
3. You cannot define a function in a function.
4. The algorithm must have output, but it does not have input.
5. Break can be used for loop structures and switch statements.
6. the comma operator has the lowest level.
Chapter 1
1) Check for valid user identifiers:
A legal requirement is that it consists of letters, numbers, and underscores. An error occurs when other elements exist.
And the first one must be a letter or an underscore. If the first digit is a number, the error occurs.
Keywords cannot be used as user identifiers. Main define scanf printf is not a keyword. If is a User Identifier. Because if

The first letter in is capitalized, so it is not a keyword.
2) valid form of real data:
2.333e-1 is valid, and the data is 2.333 × 10-1.
Exam tip: e must be a number before E, and E must be an integer ..
3) valid form of character data ::
'1' indicates that the character occupies one byte, and "1" indicates that the string occupies two bytes (including one ending symbol ).
The ASCII value of '0' is 48, the ASCII value of 'A' is 97, and the ASCII value of 'A' is 65.
4) The integer type is generally two bytes, the dense type is one byte, and the double precision is generally four bytes:
During the examination, it is generally said that the system is compiled in 16 bits or 32 bits. In this case, do not worry about it. Generally, the integer type is two bytes in bytes.

It is a byte, and the double precision is generally 4 bytes.
5) Escape Character test:
In the program, int A = 0x6d is to give the number of a hexadecimal value to the variable A. Note that the 0x here must exist.
In the program, int A = 06d is an octal form.
In escape characters, '/x6d' is valid, 0 cannot be written, and X is lowercase.
'/100' is legal, and 0 cannot be written.
'/100' is invalid because 8 is not allowed.
6) Priority of arithmetic operators:
At the same level, some are from left to right, and some are from right to left.
7) Forced type conversion:
It must be (INT) a rather than int (a). Note that there are Parentheses in the type.
Note the differences between (INT) (A + B) and (INT) A + B. The first is to transform a + B, and then a transformation plus B.
8) Test the expression:
If it is an expression, there must be a number.
Value assignment expression: the expression value is the leftmost value, a = B = 5; the expression is 5, and a constant cannot be assigned a value.
Auto-increment and auto-increment expressions: assume a = 5, ++ A (6), and a ++ (5 );
Operating Mechanism: ++ a first adds the value of the variable to 1, then puts the obtained value into variable A, and then uses this
The number of ++ A expressions is 6, and a ++ first uses the value of this expression as 5, and then adds the value of a to 6,
Put it in variable. After ++ A and A ++ are executed, if A is used in the following program, it is 6 of the variable.
Exam tips: ++ is used first and then, ++ is used later.
Comma expression: the lowest priority. The value of the expression is the value of the expression on the rightmost side of the comma.
The value of the expression (2, 3, 4) is 4.
9) Bit operations:
There will be one or two exam questions.
General Solution: almost all bitwise operations must be handled in this process (convert decimal to binary and then decimal ).
Example 1: Char A = 6, B;
B = A <2; in this case, the decimal 6 of A must be converted into binary before bitwise computation.
Example 2: Remember,
Example 3: If no data is removed, <remove one digit left by 2;> remove one digit right by two.
10) The 018 value is invalid, and the octal value does not have 8 values. Every 8 to 1.
11) % The symbols must be integers on both sides. If it is not an integer, an error occurs.
12) Three cases of integer decimal dropping:
1. int A = 1.6;
2. (INT);
3,

Chapter 2
1) formats of printf functions:
% D corresponds to an integer; % C corresponds to a character; % F corresponds to a single precision, and so on. Width, left alignment, etc.
% LD corresponds to long int; % lf corresponds to double.
2) Format of scanf functions:
Note that the second part of the function is an address like & A, not;
Scanf ("% d % * D % d", & A, & B, & C); skips the third input data.
3) putchar and getchar functions:
Char A = getchar () has no parameters. You can get a character from the keyboard and give it to variable.
Putchar ('y') Outputs character Y to the screen.
4) How to Implement the interchange of values in two variables X and Y (back down is required)
You cannot convert x = Y, y = x; to an intermediate variable t = x; X = y; y = T.
5) how to implement the Program of retaining three decimal places and rounding the fourth decimal places (requirements should be backed down)
This has promotion significance. Note that X = (INT) x removes the decimal part.

Chapter 3
Note: The C language uses non-0 to indicate true logic, and 0 to indicate false logic.
1) relational expression:
The value of an expression can only be 1 (true) or 0 (false)
1 is obtained when the expression of the link is true. For example, 9> 8 is true, so the value of the expression is 1;
2) logical expression:
It can only be 1 (true) or 0 (false)
A) Total! Three logical operators.
B)!> &> | Priority.
C) Short Circuit. You prefer to take the test.
D) It indicates that X is greater than 0 and smaller than 10. 0 <x <10 is not acceptable (remember ). Is to calculate 0 first <X to get the result 1 or 0; then 0, or 1 and

10 is always true (1 ). Therefore, you must use (0 <X) & (x <10) to indicate that the value is greater than 0 and smaller than 10.
3) If statement
Else is a combination of the nearest if and no else.
4) conditional expressions:
Expression 1? Expression 2: expression 3
Note that when the value is not 0, it is the value of expression 2. If the value is 0, it is the value of expression 2.
Exam tips: true or false.
5) switch statement:
A) Be sure to note the difference between the break and the non-break. In the two examples on the book (34 pages), if there is no break, if there is a matching case, the rest must be executed.

Line. If there is a break, the swiche statement is directly jumped out.
B) The switch can only be used with the break and cannot be used with the continue.

Chapter 4
1) Three cycle structures:
A) For (); While (); Do-while.
B) The for loop must contain two semicolons. Do not forget them.
C) when writing a program, you must note that the loop must have the condition for ending. Otherwise, it becomes an endless loop.
D) The semicolon of the last while (); of the do-while () loop cannot be lost. (Beware of computer errors)
2) Difference between break and continue
Memory method:
Break: It means breaking (breaking the entire loop), so when you see break, you can exit a loop.
Continue: It means to continue (continue loop operation), but to end this loop, it means that the remaining statements in the loop are no longer executed, jump to the beginning of the loop, and then judge

Break the cycle condition to carry out a new round of cycle.
3) nested loop
There are loops in the loop. This is complicated. We need to patiently calculate them one by one. Generally, remember that the two layers process two-dimensional arrays.
4) while (C = getchar ())! = '/N') and while (C = getchar ()! = '/N')
First look at a = 3! = 2 and (A = 3 )! = 2:
(! = The level of the number is higher than =, so the first one counts 3 first! = 2) the first value of A is 1, and the second value of A is 3.
Note: brackets are important here.

Chapter 5
Function: a program with certain functions;
1) function parameter, return value ():
Main ()
{
Int A = 5, B = 6, C;
C = add (A, B );
Printf ("% d", c );
}

Call a function
A and B are real parameters.
The value of the entire function is
The Return Value of the add function.
Int add (int x, int y)
{
Int Z;
Z = x + y;
Return Z;
}
Called function
X and Y are formal parameters.
The Return Value of the function is an integer.

Z is the result calculated by the Add function. It is the value returned by the function to the main program.
The program is executed sequentially from top to bottom. When the Add function is met, the values of A and B are passed to the calling function. The program is temporarily interrupted and a value is returned. When a returned value is obtained

And then proceed sequentially.
2) Be sure to pass between parameters
The difference between the input parameter and the input address. (Exam Focus)
If a value is passed, the changes of the form parameter do not change the changes of the real parameter.
If the input address is used, the changes in the form parameters may change the real parameters.
3) function declaration:
Must include: function name, function return type, and function parameter type.
The parameter name is not required.

Chapter 6
The essence of pointer variables is to put addresses, while general variables are to put numbers.
* P and P in int * P:
* P can be used as a variable. * The function is to take the values in the following address p.
P is used as an address.
* The difference between P ++ and (* P) ++: it is important to correct the incorrect question.
* P ++ indicates that the address changes.
(* P) ++ indicates that the value must change.
Three principles: (exam Focus)
Array name: the address of the first element. The array name cannot be automatically added. It is an address constant name. (Tested many times)
Function Name: the entry address of the function.
String constant name: the address of the first character.

Chapter 7
1 important concepts of one-dimensional array:
A discussion of the array a [10.
1. A indicates the array name, which is the address of the first element, that is, the address of element a [10.
2. A is an address constant. Therefore, if a ++ or a = a + 2 is assigned a value, it is incorrect.
3. A is a one-dimensional array name, so it is a column pointer, that is, a + 1 is a hop column.
A [3] [3.
1. A indicates the array name, which is the address of the first element, that is, the address of element a [10.
2. A is an address constant. Therefore, if a ++ or a = a + 2 is assigned a value, it is incorrect.
3. A is a two-dimensional array name, so it is a row pointer, that is, a + 1 is a hop row.
4. A [0], a [1], and a [2] are also address constants. You cannot assign values to them. They are all column pointers, A [0] + 1, a [1] + 1, a [2] + 1 are all skip columns.
5. Note that a and a [0], a [1], and a [2] are different. Their base types are different. The former is a row element, and the latter is a column element.
Tips for using two-dimensional arrays:
If there is a question like a [3] [3] = {1, 2, 3, 4, 5, 6, 7, 8, 9.
Step 1: Write them as the first column, the second column, and the third column.
A [0] à 1 2 3-> first line
A [1] à 4 5 6-> Row 2
A [2] à 7 8 9-> Row 3
Step 2: This is a simple question:
* (A [0] + 1) We know that it is the first element in the first row that jumps to the next column. Here it is the [0] [1] element, so it is 1.
* (A [1] + 2) We know that the first element of the second row jumps to the next two columns. Here is the [1] [2] element, so it is 6.
Remember: as long as it is a two-dimensional array question, it must be written in the above format, and then do the question, this will be relatively simple.
Array initialization, one-dimensional and two-dimensional, one-dimensional can not be written, two-dimensional second must be written
Int A [] = {1, 2} is valid. Int A [] [4] = {2, 3, 4} is valid. But int A [4] [] = {2, 3, 4} is invalid.
Row pointer in two-dimensional array
Int A [1] [2];
A is a row pointer, and a + 1 jumps to an array element. Match (*) P [2] pointer
A [0], a [1] is a column pointer. A [0] + 1 jumps to an array element. Used with * P [2] pointer Array
Remember to take off your clothes:
A [2] to * (a + 2) A [2] [3] To * (a + 2) [3] and then to * (a + 2) + 3)
This idea is very important!
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.