“From today onwards, study hard and make progress every day”
Repetition is the best method for memory; spend one minute each day to remember the basics of C language.
1. Basic Understanding of C Language
- 1.Features of C Language
- • Procedural/Structured Language
- • Efficiency (close to hardware)
- • Strong portability (standard library specifications)
- • Direct memory manipulation with pointers
- • Compilers: GCC, Clang, MSVC
- • Recommended IDEs: VS Code, CLion, Dev-C++
- • Compilation Process: Preprocessing → Compilation → Assembly → Linking
2. Core Syntax System
1. Program Structure
#include <stdio.h> // Preprocessing directive
int main() { // Main function entry
printf("Hello World!");
return 0; // Return value
}
2. Data Types
Type | Example | Size (32-bit) |
<span>int</span> |
<span>int a = 10;</span> |
4 bytes |
<span>float</span> |
<span>float b=3.14;</span> |
4 bytes |
<span>char</span> |
<span>char c='A';</span> |
1 byte |
<span>double</span> |
<span>double d=3.14159;</span> |
8 bytes |
- • Derived types: Arrays, Structures, Enumerations, Unions
3. Operators
- • Arithmetic:
<span>+ - * / %</span>
- • Relational:
<span>> < == !=</span>
- • Logical:
<span>&& || !</span>
- • Bitwise:
<span>& | ^ ~ << >></span>
4. Control Flow
- • Branching:
<span>if-else</span>
/<span>switch-case</span>
- • Loops:
<span>for</span>
/<span>while</span>
/<span>do-while</span>
- • Jumps:
<span>break</span>
/<span>continue</span>
/<span>goto</span>
3. Core Advanced Features
1. Functions
int add(int x, int y) { // Function definition
return x + y;
}
- • Parameter passing methods: Pass by value vs Pass by address
- • Recursive calls
- • Function pointers:
<span>int (*func)(int, int) = add;</span>
2. Pointers
- • Basic operations:
int var = 20; int *ptr = &var; // ptr points to the address of var *ptr = 30; // Modify variable value through pointer
- • Pointer arithmetic:
<span>ptr++</span>
(address offset) - • Multi-level pointers:
<span>int **pptr = &ptr;</span>
3. Memory Management
- • Dynamic allocation:
int *arr = (int*)malloc(10*sizeof(int)); free(arr); // Must manually free
- • Common errors: Memory leaks, Dangling pointers
4. File Operations
FILE *fp = fopen("test.txt", "r");
fscanf(fp, "%s", buffer);
fclose(fp);
4. Advanced Features
- 1.Structures and Unions
struct Student { char name[20]; int age; };
- 2.Preprocessor
- • Macro definitions:
<span>#define PI 3.14</span>
- • Conditional compilation:
<span>#ifdef DEBUG</span>
- • Header files (
<span>.h</span>
) declarations - • Source files (
<span>.c</span>
) implementations - •
<span>extern</span>
keyword
5. Typical Application Scenarios
- 1. Embedded Development (Microcontroller Programming)
- 2. Operating System Development (Linux Kernel)
- 3. High-Performance Computing (Algorithm Optimization)
- 4. Hardware Driver Development
6. Suggested Learning Path
- 1.Beginner Stage: Master basic syntax → Practice classic algorithms (e.g., sorting)
- 2.Intermediate Stage: Deepen knowledge of pointers/memory → Implement data structures (linked lists/stacks/queues)
- 3.Project Practice: Develop small systems (e.g., student management system)
Appendix: Common Mistakes
- • Array out-of-bounds access
- • Confusion between
<span>=</span>
and<span>==</span>
- • Uninitialized pointers
- • Forgetting to add
<span>&</span>
in<span>scanf</span>
———- End ———-
[Special Statement: All articles in this public account are original or authorized by the author, please feel free to consume~~]
“If you like C, please like it” Click the bottom right to see
“