C语言函数速查手册

本手册提供C语言中的常用函数列表,帮助开发者快速查找和理解函数的用途、参数及返回值。
- **printf**:格式化输出字符串。需要指定格式控制符来定义输出的类型(如整数、浮点数等)以及如何格式化这些数据。
```c
printf("Hello, world!");
```
- **scanf**:从标准输入流中读取数据到变量。同样需要使用格式控制符来指定要读取的数据类型和存储变量的位置。
```c
int num;
scanf("%d", #);
```
- **strlen**:计算字符串的长度,不包括结尾的空字符`0`。
```c
char str[] = "Hello, world!";
int len = strlen(str);
printf("Length of the string is %d
", len);
```
- **strcpy**:将一个字符串复制到另一个字符串中,包括结尾的空字符`0`。
```c
char dest[20];
strcpy(dest, "Hello, world!");
printf("Destination string is %s
", dest);
```
- **strcmp**:比较两个字符串是否相等。如果返回值为零,则表示两个字符串相同;否则不同。
```c
char str1[] = "Hello";
char str2[] = "World";
int result = strcmp(str1, str2);
if (result == 0) {
printf("Strings are equal
");
} else {
printf("Strings are not equal
");
}
```
- **malloc**:动态分配内存。需要指定要分配的内存大小,并返回一个指向该内存块的指针。
```c
int *ptr = (int *)malloc(sizeof(int));
*ptr = 42;
printf("The value is %d
", *ptr);
free(ptr); // 释放内存
```
- **free**:释放动态分配的内存。需要传入一个指向要释放的内存块的指针。
```c
int *ptr = (int *)malloc(sizeof(int));
*ptr = 42;
printf("The value is %d
", *ptr);
free(ptr); // 释放内存
```
chm 文件大小:96.48KB