C语言笔记——常见的头文件及其包含的内置函数

<stdio.h> : printf, scanf, getchar, putchar

<conio.h> : getch, putch

<time.h>: time

<string.h>: strcpy, strcmp, strchr, size_t_strlen, strupr, strlwr, strcat

<ctype.h>: isupper(是否大写字母), islower, isalpha(是否字母), isdigit, toupper(返回大写字母), tolower

注意 printf("%d\n", isdigit('9')); 和printf("%d\n", isdigit(9)); 的区别,分别返回的是非0值和0值。因为传入的是ASCII码。

<math.h>: ceil, floor, round, sqrt, pow, abs

<stdlib.h>: srand(设置随机数生成种子), rand(取随机数), exit, system, malloc(动态内存分配), calloc, realloc(重新分配), free

srand一般与time、rand联用,随机数随时间不同而不同,srand(time(NULL));  int ex = rand();

system用法(执行dos命令):

1. system("pause");                      // 冻结屏幕,便于观察程序的执行结果

2. system("cls");                            // 清屏操作(可作简单的动画效果)

3. system("color 4E");                   // 修改背景色及前景色(4代表背景色为红色,E代表前景色为淡黄色)

4. system("shutdown /r /t 180");   // 设置自动关机(180s后自动关机)

5. system("shutdown /a");             // 取消自动关机

malloc用法:

int * ptr_ex;
ptr_ex = (int *)malloc(sizeof(int) * 5); // 为指针ptr_ex动态分配了20个字节(5个整型)的空间,指针变成了数组

free(ptr_ex);      // 释放动态分配的内存

ptr_ex = NULL;

calloc用法(与malloc作用类似,不同之处是malloc需强制转换,calloc参数有两个及默认初始化数组元素):

ptr_ex =calloc(5,sizeof(int));

realloc用法(需强制转换,参数有两个,不默认初始化数组元素)

ptr_ex = (int *)realloc(ptr_ex, sizeof(int) * 15);

free用法:

1. 必须是通过malloc, calloc, realloc分配内存的指针

2. 释放的指针必须是初始分配的地址,进行运算后需要恢复


  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值