IT老鸟,信息安全硕士。
分类: C/C++
2011-10-22 15:21:31
指针也是值传递.这样才能改值.
#include "process.h"
#include "string.h"
#include "stdlib.h"
void testmemory(char **ptr){
*ptr=(char*)malloc(sizeof(char)*256);
printf("strlen(ptr)=%d\n",strlen(*ptr));
//return ptr;
}
int main(int argc, char* argv[])
{
char* ptr1;
char a[100];
testmemory(&ptr1);
printf("strlen(ptr1)=%d\n",strlen(ptr1));
free(ptr1);
system("PAUSE");
return 0;
}
blacksapper2011-11-01 17:21:30
blacksapper2011-11-01 17:18:03
chenliangmoran2011-10-31 13:55:01
blacksapper2011-10-31 10:48:38