Monday, March 12, 2007

placement form new

#include
int main(int argc, char* argv[])
{
char *pTest = new char[10];

char* pStr = new(pTest) char[10];

strcpy(pTest,"Rammohan");
strcpy(pTest,"Sundar");

printf("%s",pStr);

if(pStr)
{
delete pStr;
}
getch();
return 0;
}

output is : Sundar
Only one pointer is used...

No comments: