理学c库函数ppt模版课件

理学c库函数ppt模版课件

ID:19468518

大小:310.00 KB

页数:32页

时间:2018-10-02

理学c库函数ppt模版课件_第1页
理学c库函数ppt模版课件_第2页
理学c库函数ppt模版课件_第3页
理学c库函数ppt模版课件_第4页
理学c库函数ppt模版课件_第5页
资源描述:

《理学c库函数ppt模版课件》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、C语言回顾课程概述math.hstdio.hstdlib.hmalloc.hstring.hassert.h动态存储分配(malloc.h)函数名:malloc功能:内存分配函数 用法:void*malloc(unsignedsize);程序例:#include/*For_MAX_PATHdefinition*/#include#includevoidmain(void){char*string;/*Allocatespaceforapathname*/string=mall

2、oc(_MAX_PATH);if(string==NULL)printf("Insufficientmemoryavailable");else{printf("Memoryspaceallocatedforpathname");free(string);printf("Memoryfreed");}}动态存储分配(malloc.h)函数名:free功能:释放已分配的块 用法:voidfree(void*ptr);程序例:#include#include#include

3、.h>intmain(void) {char*str;/*allocatememoryforstring*/str=malloc(10);/*copy"Hello"tostring*/strcpy(str,"Hello");/*displaystring*/printf("Stringis%s",str);/*freememory*/free(str);return0; }动态存储分配(malloc.h)函数名:realloc功能:改变已分配内存的大小,ptr为已分配有内存区域的指针,newsize为新的长度,返回分配好的内存指

4、针;用法:void*realloc(void*ptr,unsignednewsize)程序例:#include#include#includevoidmain(void){long*buffer;size_tsize;if((buffer=(long*)malloc(1000*sizeof(long)))==NULL)exit(1);size=_msize(buffer);printf("Sizeofblockaftermallocof1000longs:%u",size

5、);/*Reallocateandshownewsize:*/if((buffer=realloc(buffer,size+(1000*sizeof(long))))==NULL)exit(1);size=_msize(buffer);printf("Sizeofblockafterreallocof1000morelongs:%u",size);free(buffer);exit(0);}动态存储分配(malloc.h)函数名:calloc功能:分配nelem个长度为elsize的内存空间并返回所分配内存的指针;用法:void

6、*calloc(size_tnum,size_tsize);程序例:#include#includevoidmain(void){long*buffer;buffer=(long*)calloc(40,sizeof(long));if(buffer!=NULL)printf("Allocated40longintegers");elseprintf("Can'tallocatememory");free(buffer);}类型转换函数(stdlib.h)函数名:atof功能:把字符串转换

7、成双精度数,并返回这个数,错误返回0;用法:doubleatof(constchar*nptr);程序例:#include#includeintmain(void) {floatf;char*str="12345.67";f=atof(str);printf("string=%sfloat=%f",str,f);return0; }类型转换函数(stdlib.h)函数名:atoi功能:把字符串转换成整型数,并返回这个数,错误返回0;用法:intatoi(constchar*nptr);程序例

8、:#include#includeintmain(void) {intn;char*str="12345.67";n=atoi(str);printf("string=%sinteger=%d

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。