前言
这里只是简单列出C语言的知识点
1. 基础语法
1.1 数据类型
1 2 3 4
| int a = 10; float b = 3.14; double c = 3.141592; char d = 'A';
|
1.2 运算符
- 算术运算符:
+ - * / %
- 关系运算符:
== != > < >= <=
- 逻辑运算符:
&& || !
2. 流程控制
2.1 条件语句
1 2 3 4 5 6 7
| if(condition) { } else if(condition2) { } else { }
|
2.2 循环结构
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| for(int i=0; i<10; i++) { printf("%d\n", i); }
while(condition) { }
do { } while(condition);
|
3. 函数
1 2 3 4 5 6 7
| int add(int a, int b) { return a + b; }
int result = add(3, 5);
|
4. 数组与指针
4.1 数组
1 2
| int arr[5] = {1,2,3,4,5}; int matrix[2][3] = {{1,2,3}, {4,5,6}};
|
4.2 指针
1 2 3
| int var = 20; int *ptr = &var; printf("%d", *ptr);
|
5. 结构体与联合体
5.1 结构体
1 2 3 4 5 6 7
| struct Student { char name[20]; int age; float score; };
struct Student stu1 = {"Alice", 20, 90.5};
|
5.2 联合体
1 2 3 4 5
| union Data { int i; float f; char str[20]; };
|
6. 文件操作
1 2 3 4
| FILE *fptr; fptr = fopen("file.txt", "w"); fprintf(fptr, "Hello World"); fclose(fptr);
|
7. 内存管理
1 2
| int *ptr = (int*)malloc(5*sizeof(int)); free(ptr);
|
8. 预处理器
1 2 3 4 5
| #define PI 3.14159 #include <stdio.h> #ifdef DEBUG #endif
|
9. 常用标准库
<stdio.h>: 输入输出函数
<stdlib.h>: 内存分配等通用函数
<string.h>: 字符串处理函数
<math.h>: 数学函数
10. 重要特性
- 面向过程编程
- 直接内存访问能力
- 高效的底层控制
- 可移植性强
版权声明: 此文章版权归曦曦所有,如有转载,请注明来自原作者