Common codes:
-
Program Entry:
int main()
The function is used to define the entry point of the program . -
Output: Use the function to print output
printf()
to the console . -
Input: Use
scanf()
the function to receive user input . -
Conditional judgment: Use
if-else
the statement to execute different code blocks according to the condition . -
Looping constructs: Use
for
loops,while
loops, or loops to implement repeated executiondo-while
of code . -
Arrays: Define and manipulate one-dimensional or multidimensional arrays .
-
String processing: Use string-related functions , such as
strlen()
,strcpy()
,strcat()
etc. for string processing.
specific function:
-
Mathematics library functions: such as
sqrt()
(square root),pow()
(exponentiation),sin()
,cos()
,tan()
(trigonometric functions), etc. -
File operation functions: such as
fopen()
(open file),fscanf()
(read input from file),fprintf()
(write output to file),fclose()
(close file), etc. -
Memory operation functions: such as
malloc()
(dynamic memory allocation),free()
(release memory),memcpy()
(memory copy), etc.
Complex concepts:
-
Pointers: Understand the concept, usage and pointer operators
*
and&
of pointers . -
Structures: Learn how to define and use structures , and how to access structure members .
-
Dynamic memory allocation: Master the methods of dynamically allocating memory, such as using
malloc()
,calloc()
andrealloc()
. -
File pointers: understand the concept of file pointers, and learn how to open, read and write files .
Specific functions:
-
Input validation: Write code to validate that user input is as expected, and handle cases where input is not valid.
-
Sorting algorithm: Implement common sorting algorithms, such as bubble sort, insertion sort, selection sort, quick sort, etc.
-
Search algorithm: implement common search algorithms, such as linear search, binary search, etc.
-
Data structure: Understand and implement common data structures, such as linked list, queue, stack, etc.
-
Multi-file programming: Learn how to split your code into multiple files and develop modularly in your application.
-
Error Handling: Use error codes or exception handling mechanisms to handle error conditions that may arise in your program.
Some basic grammar rules of C language:
-
Notes:
- Single-line comments:
//
start with , followed by the content of the comment. (C++ comment style) - Multi-line comments:
/*
start with,*/
end with, and comment content in the middle. (C language comment style)
- Single-line comments:
-
Identifier:
- Identifiers are used to name variables, functions, structures, etc. Identifiers consist of letters, numbers, and underscores , and cannot begin with a number.
- Uppercase and lowercase letters are treated as different characters.
-
keywords:
- There are some reserved keywords in C language , such as
int
,if
,else
,while
etc. These keywords have special meanings and cannot be used as identifiers.
- There are some reserved keywords in C language , such as
-
Variable declaration and definition:
- Before using a variable, you need to declare or define the variable and specify its data type.
- When declaring a variable, you need to specify the data type and name of the variable, eg
int num;
. - When defining a variable, in addition to specifying the data type and name of the variable, you can also assign an initial value to the variable , for example
int a= 0;
.
-
function:
- Functions provide code encapsulation and reuse mechanisms.
- A function consists of a function name, parameter list, return type, and function body, eg
int add(int a, int b) { return a + b; }
.
-
statement:
- A program in C language consists of a series of statements, and each statement ends with a semicolon
;
. - Common statements include assignment statements, conditional statements, and loop statements .
- A program in C language consists of a series of statements, and each statement ends with a semicolon
-
type of data:
- There are basic data types in C language, such as integer types (such as
int
,short
), floating point types (such asfloat
,double
), character types (such aschar
), etc. - You can also use
typedef
keywords to define custom data types.
- There are basic data types in C language, such as integer types (such as
-
operator:
- C language supports various operators, such as arithmetic operators, relational operators, logical operators, bitwise operators, etc.
at last
The above are some common grammatical concepts and functions in C language and some basic grammatical rules of C language . Hope to help you! ! !
Friends who have seen it, click three times with one button. Your support makes me more motivated to create and share. I hope it will always bring you surprises and gains.