資源簡介
利用malloc和 calloc函數實現動態內存的分配;利用free函數實現動態內存的釋放;
利用realloc函數實現調整內存空間的大小;
利用鏈表實現動態內存分配。
1、 了解靜態內存與動態內存的區別;
2、 理解動態內存的分配和釋放原理;
3、 掌握如何調整動態內存的大小;
4、 利用鏈表實現動態內存分配。

代碼片段和文件信息
#include?
#include?
#include?
char?*upcase(char?*inputstring);
int?main(void)
{
char?*str1?*str2;
str1=upcase(“Hello“?);
str2=upcase(“YYB“);
printf(“str1=%s?str2=%s\n“?str1?str2);
free(str1);
free(str2);
return?0;
}
char?*upcase(char?*inputstring)
{
char?*newstring;
int?counter;
if(!(newstring=malloc(strlen(inputstring)+1)))
{
printf(“ERROR?ALLOCATING?MEMORY!?\n“);
exit(255);
}
strcpy(newstring?inputstring);
for(counter=0;?counter {
if(newstring[counter]>=97&&newstring[counter]<=122)
newstring[counter]-=32;
}
return?newstring;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-03-07?16:00??1400002100?楊永博?實驗三?內存分配與回收\
?????文件???????68096??2018-03-07?16:00??1400002100?楊永博?實驗三?內存分配與回收\實驗三??內存分配與回收.doc
?????目錄???????????0??2018-03-07?15:48??1400002100?楊永博?實驗三?內存分配與回收\源代碼\
?????文件????????6899??2017-04-06?11:43??1400002100?楊永博?實驗三?內存分配與回收\源代碼\test01
?????文件?????????633??2017-04-06?11:43??1400002100?楊永博?實驗三?內存分配與回收\源代碼\test01.c
?????文件????????6992??2017-04-06?11:43??1400002100?楊永博?實驗三?內存分配與回收\源代碼\test02
?????文件?????????820??2017-04-06?11:43??1400002100?楊永博?實驗三?內存分配與回收\源代碼\test02.c
?????文件????????6192??2017-04-06?11:43??1400002100?楊永博?實驗三?內存分配與回收\源代碼\test03
?????文件????????1873??2017-04-06?11:43??1400002100?楊永博?實驗三?內存分配與回收\源代碼\test03.c
- 上一篇:zemax宏語言計算二組元凸輪曲線
- 下一篇:Linux設備驅動
評論
共有 條評論