Current location - Training Enrollment Network - Books and materials - A summary of the basic knowledge of C language
A summary of the basic knowledge of C language
The basic knowledge of C language is summarized as follows:

1, getting started?

2. Data type?

Data type:

1. Basic data type:

1. 1. Integer: int 4 bytes.

1.2. Character type: char 1 byte.

1.3. Real number type (floating point type)

1.3. 1. Single precision type: floating point 4 bytes.

1.3.2.Double type: double 8 bytes.

2. Structure type:

2. 1. enumeration type

2.2. Array types

2.3. Structure type

2.4.*** User Type

3. Pointer type:

4. Empty type:

3. Print format statement?

%d: decimal integer;

%c: single character;

%s: string;

%f:6 decimal places;

4. Constant?

The quantity whose value is constant becomes a constant;

Define character constants (note that there is no following; )

5. operator

5. 1. Arithmetic operators:+,-,*,/,%,++,-; Before++/-,calculate first, then take the value. ++/,value first and then operation;

5.2. Assignment operator:

5.3. Relational operators;

5.4. Logical operators;

5.5. Tripartite operators:

The expression 1? Expression 2: Expression 3;

6. daffodil number calculation?

Output all three-digit daffodil numbers.

The so-called "daffodil number" refers to a three-digit number, and the cubic sum of its digits is equal to this number. For example, 153 is the daffodil number,11+555+333.

7. Print regular triangle *?

8. The infamous goto statement?

Rarely used

9. formally participate in the actual participation?

Formal parameters: formal parameters are parameters used when defining the function name and body, and are used to receive the parameters passed in when calling the function;

Argument: Argument is the parameter of the function passed when calling.

The formal parameters and arguments of a function have the following characteristics:

Parameter allocates memory cells only when called, and releases the allocated memory cells at the end of the call. Therefore, formal parameters are only valid inside the function. After the function call ends and returns to the tonic function, the parameter variable can no longer be used.

Parameters can be constants, variables, expressions, functions, etc. No matter what kind of quantity, there must be definite values when making function calls, so that these values can be passed to formal parameters. Therefore, it is necessary to use assignment and other methods in advance to get the definite value of real parameters.

When passing parameters, the number, type and order of actual parameters and formal parameters should be strictly consistent, otherwise there will be an error of type mismatch.

10. Notice the function return value?

Note: void functions can have execution code blocks, but they cannot have return values. In addition, if there is a return statement in the void function, you can only end the function. Its format is: return;

1 1. Recursive?

12. Variable storage category! ?

12. 1. Lifecycle Split Storage Mode

According to the lifecycle of variables, C language can be divided into static storage and dynamic storage.

Static storage mode: refers to the mode of allocating fixed storage space when the program is running. Static storage area stores variables that exist in the whole program execution process, such as global variables.

Dynamic storage mode: refers to the mode of dynamically allocating storage space according to needs during the running of the program. Variables stored in dynamic storage area are established and released according to the needs of program operation, which usually include: function parameters; Automatic variable; Site protection and return address when calling function.

12.2. storage type division

There are four types of storage in C language: automatic, static, register and external.

The variable defined by the keyword auto is an automatic variable, and auto can be omitted. If auto is not written, it is implicitly defined as "automatic storage category" and belongs to dynamic storage mode.

Static is a static variable. If it is defined inside a function, it is called a static local variable. If defined outside a function, it is called a static external variable.

Note: static local variables belong to the category of static storage, and the storage units allocated in the static storage area will not be released during the whole running period of the program; Static local variables are given initial values at compile time, that is, they are given initial values only once; If no initial value is assigned when defining local variables, the initial value will be automatically assigned to 0 (for numeric variables) or null characters (for character variables) at compile time for static local variables.

In order to improve efficiency, C language allows the values of local variables to be placed in registers in CPU, which are called "register variables" and declared with the keyword register.

Note: Only local automatic variables and formal parameters can be used as register variables; The number of registers in a computer system is limited, so it is impossible to define any number of register variables. Local static variables cannot be defined as register variables.

Variables declared with extern are external variables, and the meaning of external variables is that functions can call variables defined after functions.

13. Internal function external function! ?

Functions in C language that cannot be called by other source files are called internal functions, which are defined by static keywords, so they are also called static functions, in the form of:

Static [data type] function name ([parameter])

Static here is a restriction on the scope of the function and can only be used in the source file, so it is no problem for internal functions with the same function name to appear in different files.

In C language, functions that can be called by other source files are called external functions, which are defined by the extern keyword in the following form:

External [data type] function name ([parameter])

C language stipulates that when the scope of a function is not specified, the system will think it is an external function by default, so extern can also be omitted when defining an external function. Extern 14. Array Array: a continuous memory space with a fixed size and a consistent data type can be omitted. Declaration of array: data type array name [length n]

Data type array name [length n]= {element 1, element 2, element 3, ...};

Data type array name [] = {element 1, element 2, element 3, ...};

Number class type array name [length n]; Array name [0] = element1; Array name [1] = element 2; ..... Note: 1 and the subscripts of the array all start with 0;

2. When initializing an array, the number of elements in the array cannot be greater than the declared array length.

3. If the first initialization method is adopted, when the number of elements is less than the length of the array, the redundant array elements are initialized to 0; 4. When the array is not initialized after declaration, the initialization elements of array elements of static and extern types are 0, and the initialization values of array elements of auto type are uncertain.

15. Array traversal

Bubble sorting of arrays

The idea of bubble sorting: compare adjacent elements with each other, and put the larger numbers behind until all the numbers are sorted.

Strings and arrays

In C language, there is no way to directly define the data type of substring. You need to use an array to define the required string in the following format:

char string name[length]= " string content ";

Character string name [length] = {'string 1',' string 2', ...,' string n',' \ 0'};

note:

The length in [] can be omitted;

In the second way, the last element must be' \0', indicating the end;

The second way can't write Chinese! ; When outputting a string, use: printf("%s ",character array name); Or puts (character array name);

16. String function?

Strlen(s): get the length s of the string;

Strcmp(s 1, s2): compare strings; When comparing, the string will be converted into ASCII code and then compared. The return result is 0, which means that the ASCII code values of s 1 and s2 are equal. The return result is 1, indicating that s 1 is an ASCII code greater than s2, and the return result is-1, indicating that s 1 is an ACSII code less than s2.

Strcpy(s 1, s2): string copy; S2 will replace the contents in s 1;

Strcat(s 1, s2) splices S2 after s 1; Note: the length of s 1 should be enough!

Atoi(s 1) converts a string into an integer!

17.

Data type array name [constant expression 1]...[ constant expression n];

The initialization of multidimensional arrays is similar to that of one-dimensional arrays, and there are two kinds:

Data type array name [constant expression 1][ constant expression 2]...[ constant expression n] = {{ value 1, ..., value n}, {value 1, ... value n}, ..., {value 1.

Data type array name [constant expression 1][ constant expression 2]...[ constant expression n]; Array name [subscript 1][ subscript 2]...[ subscript n] = value;

Multidimensional array initialization should pay attention to the following matters:

When using the first initialization, the array declaration must specify the dimension of the column. Because the system will allocate space according to the total number of elements in the array, when the total number of elements and the dimension of the column are known, the dimension of the trip will be calculated directly;

When using the second initialization, the array declaration must specify the dimensions of rows and columns.

18. Traversal of multidimensional arrays?

Use nested loops

Note: Each one-dimensional subscript of a multidimensional array cannot be out of bounds!

65438+

Arrays allow you to define variables that can store the same type of data items. Structure is another user-defined data type available in C programming, which allows you to store different types of data items.

Structure is used to represent a record. Suppose you want to track the dynamics of books in the library, you may need to track the following properties of each book:

title

author

subject

Book ID

Define structure

In order to define the structure, you must use the struct statement. The struct statement defines a new data type with multiple members. The format of the struct statement is as follows:

A tag is a structural tag.

Member-list is a standard variable definition, such as int I;; Or other valid variable definitions.

Variable list structural variables are defined at the end of the structure. Before the last semicolon, one or more structural variables can be specified. The following is the way to declare the book structure:

Under normal circumstances, there must be at least two tags, a member list and a variable list. Here are some examples:

Access structure members

To access members of a structure, we use the member access operator (. ). The member access operator is the period between the name of the structural variable and the structural member we want to access. You can use the struct keyword to define variables of structural type. The following example demonstrates the use of the structure:

20.*** with the body?

* * * Object is a special data type, which allows you to store different data types in the same memory location. You can define a * * * topic with multiple members, but only one member can have a value at any time. * * * The body provides an efficient way to use the same memory location.

2 1. pointer?

22. file reading and writing?

Write file

Read file

C Language and C++ Learning Route

23. Sorting algorithm?

Ten classic sorting algorithms (dynamic demonstration+code)

24. Search algorithm?

Nine search algorithms

Interview knowledge

C Language and C++ Interview Knowledge Summary

Word processing

A comprehensive summary of string operations

27. Interpretation of General Standard Library of C Language

Interpretation of general standard library of C language

28. The most commonly used greedy algorithm in C language.

In this way, the most commonly used greedy algorithm in C language was conquered.

29. Common C language memory errors and countermeasures

Common memory errors in C language and their countermeasures

30.c language realizes the object-oriented principle.

C language realizes the object-oriented principle.

3 1.C language /C++ memory management

Can you still understand C language /C++ memory management after reading this article?

32. Talk about C language pointer again

Let's talk about the pointer again: Big Brother will clear the cloud of the C pointer for you.

Callback function of function pointer in C language

Detailed explanation of C language pointer (welfare at the end of the article)

33.c language preprocessing command

Detailed explanation of long text: C language preprocessing command

34. Efficient programming and code optimization of C language

Efficient Programming and Code Optimization of C Language

35.c language structure

The structure of C language has been conquered in this way! Worth collecting!

36. Detailed explanation of original code, complement and complement

Detailed explanation of original code, complement and complement

37.c language macro definition

On the Use of Macro Definition in C Language

38.* * * Use union, enumeration and big and small end modes in C language.

Union, Enumeration and Big-Small Mode of * * in C Language

C language can be started with zero foundation, and its grammar is the basis of many advanced programming languages, such as Java and c++;+; +; It plays a connecting role. Up you can learn advanced programming languages, down you can learn basic computer knowledge such as computer composition principle and operating system.

book

Personally, I think the first book "Aha C Language" is humorous in writing, and basic learning is very beneficial to cultivate interest.

C programming language, mechanical industry press, Brian W. Kernighan/ (America) Dennis M. Ritchie. Written by the father of C language, an introductory classic book.

C Primer Plus, People's Posts and Telecommunications Publishing House, by Stephen Plata. Can be used as a C language reference book, but also as an introduction, the content step by step, you can exercise programming ideas.

"C and the Pointer" has a profound understanding of pointers. After reading it, I am no longer afraid of pointers.

As the book "C Traps and Defects" says, "The knowledge revealed in this book can at least help you reduce 90% bugs in C code and primary C++ code", and some pits in C language development can be avoided after reading it.

Online course

1, Hao Bin c language self-study tutorial.

2. Introduction to Programming -C Language (Zhejiang University, Weng Kai)

subitem

Including C language maze, blackjack game, running stick figure, supermarket management system, typing letters, electronic clock, antithesis, Tetris, black and white chess, Huarong Road, train ticket booking management source code, Lianliankan, commodity sales system, chess, Super Mario, book management system and student performance management system.