#include <iostream>
using namespace std;
//传值调用
void GetMemory( char **p )
{
*p = (char *) malloc( 100 );
}
//引用调用
void GetMemory_1(char *&p)
{
p = (char *) malloc (100);
}
int main()
{
char *str = NULL;
char *str1 = NULL;
GetMemory( &str );
GetMemory_1( str1 );
strcpy( str, "hello world" );
strcpy( str1, "hello world1" );
cout<<str<<endl;
cout<<str1<<endl;
free(str);
free(str1);
return 0;
}
C申请内存函数
最新推荐文章于 2024-04-01 03:15:00 发布