C++二级指针
//#include "stdafx.h"
#include <iostream>
#include <cstring>
using namespace std;
int allocstr(int len, char **retptr)
{
char *p = new char;/*加 1 是为了 '\0' malloc(len + 1)*/
if (p = NULL)
return 0;
*retptr = p;
delete p;
return 1;
}
int main(){
char *string = "hello world!";
char *copystr;
if (allocstr(strlen(string), ©str)){
//strcpy(copystr, string);
printf("Copy that!\n");
}
else{
printf("out of memory!\n");
}
system("pause");
return 0;
}