#include<iostream>
using namespace std;
#include<string>
//Define a structure
void getMem(char *ptr)
{
ptr = (char*)malloc(sizeof(char)*100);
if(nullptr == ptr)
{
cout<<"getMem ptr is nullptr"<<endl;
return;
}
strcpy_s(ptr, 9, "abcd");
cout << "getMem ptr:" << ptr<< endl;
}
int main(void)
{
char* ptr = nullptr;
getMem(ptr);
if (nullptr == ptr)
{
cout << "main ptr is nullptr";
}
else
{
cout << "main ptr:" << ptr << endl;
}
system("pause");
return 0;
}
/*
getMem ptr:abcd
main ptr is nullptr请按任意键继续. . .
*/