Home Common Problem Summary of basic knowledge points of C language

Summary of basic knowledge points of C language

Oct 26, 2019 am 09:47 AM
c language Base Summarize Knowledge points

C language is an essential basic knowledge for contemporary people's study and life. It is widely used. The following is a summary of the basic knowledge of C language.

Algorithm structure:

1. Sequential structure, selection structure, loop structure; 2. Loop structure is divided into while type, until type, and for loop structure; program Flow chart;

Structured programming method:

(1) Top-down; (2) Gradual refinement; (3) Modular design; ( 4) Structured coding.

Data type:

Constants: Constants include literal constants, direct constants and symbolic constants;

Variables: C language stipulates that identifiers can only be It consists of three characters: letters, numbers and underscores, and the first character must be a letter or underscore; it must be defined before use; after each variable is defined to determine the type, the corresponding storage unit can be allocated to it at compile time ;

Integer type: integer constants include decimal, octal and hexadecimal; "%d"

Integer variable: the data is stored in binary form in memory; there is int type , short int type and long int type, the range of unsigned integer variable is -32768-32767, and the signed type is 0~65535. Long is usually defined as 32 bits, short is defined as 16 bits, int can be 32 bits It can also be 16 bits, which mainly depends on the machine word length.

Representation method of real type constants: (1) Decimal, 0.0; (2) Exponential form, 123e3

Real type variables: The storage form of real number data in memory, usually in memory It occupies 4 bytes and is divided into integer part and decimal part for storage. Real type variables are divided into float type, double type and long double type. Real data will have rounding errors.

Type of real constants: The C compilation system handles real constants as double precision.

Character array: (1) Character constants: escape characters (——line feed,——tab,——carriage return,——page feed,——backspace, ddd——1 to 3 digits Characters represented by octal numbers)

(2) Character variables: The character data storage format is actually stored in ASCII code. "%c"

String constant: a sequence of characters enclosed in double apostrophes.

Related recommendations: "php video tutorial"

The operators of C include the following types:

1. Arithmetic The combination direction of operators (- * / %) is from left to right

2. Relational operators (> < == >= <= !=)

3. Logic Operator (! && ||)

4, bitwise operator (<< >> ~ | ^ &)

5, assignment operator (= and sign extended assignment Operator)

6, conditional operator (? : )

7, comma operator ( , )

8, pointer operator (* &)

9. Seek byte operator (sizeof)

10. Forced type conversion operator ((type))

11. Component operator (. ->)

12. Subscript operator ([])

13. Other

control statements:

Complete certain control functions.

1, if()~else~

2, for()~

3, while()~

4, do~while( )

5、continue

6、break

7、switch

8、goto

9、return

Input and output of character data:

1. putchar() input character variable

2. getchar() can only accept one character

Format input and output:

1. printf (%d—integer type, %c—character type, %ld, %md, %o, %u, %s, %-m .nf, %e, %g)

2. scanf (format control, address list)

Array

Definition of one-dimensional array: Type specifier array name [constant expression]; define first and then reference; when initializing a one-dimensional array, only a part of the elements can be initialized, and the length can be specified when initializing all array elements; but if the length of the defined array is different from the provided When the initial values ​​of are different, the array length cannot be omitted.

Definition of two-dimensional array: type specifier array name [constant expression] [constant expression] To store a two-dimensional array in C language, the elements of the first row are stored first, followed by the second row. In fact, it is also stored in a one-dimensional manner. If the initial values ​​of all elements can be specified during initialization, the first dimension size can be omitted, but the second dimension cannot be omitted.

Character array: The definition and initialization are similar to those of arrays, except that single quotes are required. Character and string end marks, specified by C language, are represented by ‘’.

String processing function:

1. puts() outputs a string to the terminal

2. gets() inputs a string from the terminal String to character array and get a function value.

3. strcat() links strings in two character arrays.

4. strcpy() string copy function.

5. strcmp() compares strings.

6. The strlen() function to test the length of a string does not include ""

7. strlwr() converts uppercase letters in the string to lowercase letters.

8. strupr() converts lowercase letters in the string to uppercase letters.

Function

(1) A source program consists of multiple functions.

(2) The execution of the C program starts from the main() function;

(3) All functions are parallel;

(4) Function classification; can be divided into For standard and custom functions, they can also be divided into parameterized functions and parameterless functions.

The general form of function definition:

(1) Type identifier function name ()

1

2

3

4

{

声明部分

语句

}

Copy after login
Copy after login

(2) Type identifier function name ( Formal parameter list)

1

2

3

4

{

声明部分

语句

}

Copy after login
Copy after login

Explanation on formal parameters and actual parameters:

(1) Formal parameters specified in the definition function, when there is no function call , they do not occupy storage units in memory, and memory is allocated only when a call occurs.

(2) The actual parameter can be a constant, variable or expression; sometimes the address is passed;

(3) In the definition, the formal parameter must specify the type;

(4) The types of actual and formal parameters should be the same or assignment-compatible;

(5) C language stipulates that the data transfer of actual parameter variables to formal parameter variables is "value transfer", that is, one-way transfer , only actual parameters are passed to formal parameters, but not from formal parameters to actual parameters.

The return value of the function:

I hope that the calling function will get a certain value through function call.

(1) The return value of the function is obtained through the return statement in the function.

(2) Type of function value;

(3) If the type of function value is different from the value of the expression in the return statement, the function type shall prevail.

(4) If there is no return statement in the calling function, it does not bring back a certain value that the user needs. The function does not bring back a value, but it just does not bring back a useful value and brings back an uncertain value. value.

(5) If you don’t need to bring back any value, use void.

Function call:

Calling method:

1. Function statement;

2. Function expression;

3. Function parameters.

Declaration of the called function:

Conditions for a function to call another function:

1. The function that is called first must It is an existing function;

2. If you use a library function, you should generally use the #include command at the beginning of this file to "include" the information needed when calling the relevant library function into this file. The .h file is the suffix used for header files.

3. If a user-defined function is used, and the function is in the same file as the function using it, the called function should generally be declared in the main calling function.

4. If the called function definition appears before the calling function, it does not need to be declared.

5. If function declarations have been made outside the function before all function definitions, there is no need to declare the functions called in each calling function.

Local variables and global variables:

(1) Local variables Variables defined inside a function are internal variables, which are only valid within the scope of this function. The main function cannot use variables defined in other functions; variables with the same name can be used in different functions. They represent different objects and do not interfere with each other; formal parameters are also local variables; within a function, they can be defined in a compound statement Variables, these variables are only valid in this compound statement. This compound statement can also be called "sub-program" or "program block";

(2) Global variables, variables defined outside the function are called As external variables, global variables can increase the channels for data connection between functions. Generally, they should not be used when it is no longer necessary. They occupy storage units during the entire execution of the program, which is the universality of the function. Using global variables will make the program clearer. reduce. Also note that if an external variable and a local variable have the same name in the same source file, the external variable will be "shielded" within the scope of the local variable and will have no effect.

Storage categories of variables:

(variable value storage time) dynamic storage method, dynamically allocate storage space during program running, static storage method It refers to the way of allocating fixed storage space during the running of the program; the storage space is divided into program area, static storage area and dynamic storage area; all global variables are placed in the static storage area, and the space is allocated when the program starts and released when it is completed; dynamic The following data is stored in the storage area:

1. Function formal parameters;

2. Automatic variables;

3. On-site protection and return address when function is called; in C Every variable and function in the language has two attributes, which are the data type and the data storage type. The storage class is the way the data is stored in memory.

Storage methods are divided into static and dynamic storage categories, including four types: automatic (auto), static (static), register (register), external (extern), if not declared , if you think it is auto type, it will automatically allocate storage space and it is a dynamic storage method.

Static declares that local variables do not disappear after the function call ends but retain the original value, that is, the occupied storage unit is not released. When the function is called next time, the variable already has a value, which is the value at the end of the last function call. What needs to be explained is that if you define a local variable without assigning an initial value, the static local variable will automatically be assigned a value of 0 or a null character during compilation. Although the static local variable still exists after the function call is completed, other functions cannot reference it. Static local variables are mainly used when after initialization, the variable is only referenced without changing its value.

Register variable is a C language that allows the value of a local variable to be placed in a register in the CPU and taken out directly from the register to participate in the operation when needed. There is no need to retrieve it from the memory. However, the number of registers in the computer system is limited. , you cannot define any amount of memory arbitrarily, and local static variables cannot be defined as register variables.

Extern declares external variables to expand the scope of external variables. In a file, if the function before definition wants to reference the external variable, the variable should be declared as an external variable using the keyword extern before the reference. In multiple files, you can also use extern declaration to declare external variables. Sometimes you want some local variables to be referenced only by this file and not by other files. In this case, you can add a static when defining external variables, which enhances the versatility in the modular design of the program.

Static has two functions in declaring a variable. One is when declaring local variables. Then the space allocated for the variable always exists during the entire program execution; one is in the declaration of the global variable, the scope of the variable is limited to the operation of this file module.

Note: These methods also apply to function declarations

The above is the detailed content of Summary of basic knowledge points of C language. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

C language data structure: data representation and operation of trees and graphs C language data structure: data representation and operation of trees and graphs Apr 04, 2025 am 11:18 AM

C language data structure: The data representation of the tree and graph is a hierarchical data structure consisting of nodes. Each node contains a data element and a pointer to its child nodes. The binary tree is a special type of tree. Each node has at most two child nodes. The data represents structTreeNode{intdata;structTreeNode*left;structTreeNode*right;}; Operation creates a tree traversal tree (predecision, in-order, and later order) search tree insertion node deletes node graph is a collection of data structures, where elements are vertices, and they can be connected together through edges with right or unrighted data representing neighbors.

The truth behind the C language file operation problem The truth behind the C language file operation problem Apr 04, 2025 am 11:24 AM

The truth about file operation problems: file opening failed: insufficient permissions, wrong paths, and file occupied. Data writing failed: the buffer is full, the file is not writable, and the disk space is insufficient. Other FAQs: slow file traversal, incorrect text file encoding, and binary file reading errors.

C language multithreaded programming: a beginner's guide and troubleshooting C language multithreaded programming: a beginner's guide and troubleshooting Apr 04, 2025 am 10:15 AM

C language multithreading programming guide: Creating threads: Use the pthread_create() function to specify thread ID, properties, and thread functions. Thread synchronization: Prevent data competition through mutexes, semaphores, and conditional variables. Practical case: Use multi-threading to calculate the Fibonacci number, assign tasks to multiple threads and synchronize the results. Troubleshooting: Solve problems such as program crashes, thread stop responses, and performance bottlenecks.

How to output a countdown in C language How to output a countdown in C language Apr 04, 2025 am 08:54 AM

How to output a countdown in C? Answer: Use loop statements. Steps: 1. Define the variable n and store the countdown number to output; 2. Use the while loop to continuously print n until n is less than 1; 3. In the loop body, print out the value of n; 4. At the end of the loop, subtract n by 1 to output the next smaller reciprocal.

CS-Week 3 CS-Week 3 Apr 04, 2025 am 06:06 AM

Algorithms are the set of instructions to solve problems, and their execution speed and memory usage vary. In programming, many algorithms are based on data search and sorting. This article will introduce several data retrieval and sorting algorithms. Linear search assumes that there is an array [20,500,10,5,100,1,50] and needs to find the number 50. The linear search algorithm checks each element in the array one by one until the target value is found or the complete array is traversed. The algorithm flowchart is as follows: The pseudo-code for linear search is as follows: Check each element: If the target value is found: Return true Return false C language implementation: #include#includeintmain(void){i

C language data structure: the key role of data structures in artificial intelligence C language data structure: the key role of data structures in artificial intelligence Apr 04, 2025 am 10:45 AM

C Language Data Structure: Overview of the Key Role of Data Structure in Artificial Intelligence In the field of artificial intelligence, data structures are crucial to processing large amounts of data. Data structures provide an effective way to organize and manage data, optimize algorithms and improve program efficiency. Common data structures Commonly used data structures in C language include: arrays: a set of consecutively stored data items with the same type. Structure: A data type that organizes different types of data together and gives them a name. Linked List: A linear data structure in which data items are connected together by pointers. Stack: Data structure that follows the last-in first-out (LIFO) principle. Queue: Data structure that follows the first-in first-out (FIFO) principle. Practical case: Adjacent table in graph theory is artificial intelligence

Troubleshooting tips for processing files in C language Troubleshooting tips for processing files in C language Apr 04, 2025 am 11:15 AM

Troubleshooting Tips for C language processing files When processing files in C language, you may encounter various problems. The following are common problems and corresponding solutions: Problem 1: Cannot open the file code: FILE*fp=fopen("myfile.txt","r");if(fp==NULL){//File opening failed} Reason: File path error File does not exist without file read permission Solution: Check the file path to ensure that the file has check file permission problem 2: File reading failed code: charbuffer[100];size_tread_bytes=fread(buffer,1,siz

The concept of c language functions and their definition format The concept of c language functions and their definition format Apr 03, 2025 pm 11:33 PM

C language functions are reusable code blocks, receive parameters for processing, and return results. It is similar to the Swiss Army Knife, powerful and requires careful use. Functions include elements such as defining formats, parameters, return values, and function bodies. Advanced usage includes function pointers, recursive functions, and callback functions. Common errors are type mismatch and forgetting to declare prototypes. Debugging skills include printing variables and using a debugger. Performance optimization uses inline functions. Function design should follow the principle of single responsibility. Proficiency in C language functions can significantly improve programming efficiency and code quality.