實驗結(jié)論:通過函數(shù)參數(shù)不能帶出動態(tài)內(nèi)存,函數(shù)參數(shù)雖然為指針,其實是在函數(shù)內(nèi)部的臨時變量,只是該指針的初始值是通過調(diào)用函數(shù)賦值的。C語言函數(shù)參數(shù)都是傳值的。
#include
void getversion(char *pcVer)
{
printf("
go in getversion
");
printf("pcVer=0x%x &pcVer=0x%x
", pcVer, &pcVer);
pcVer= malloc(10);
printf("after malloc
");
printf("pcVer=0x%x &pcVer=0x%x
", pcVer, &pcVer);
return ;
}
int main()
{
char *pcVer = (char *)0x1000;
printf("in main
");
printf("pcVer=0x%x &pcVer=0x%x
", pcVer, &pcVer);
getversion(pcVer);
printf("
after getversion().
");
printf("pcVer=0x%x.", pcVer);
return 0;
}
運行結(jié)果如下: