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...
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...
Labels: Cpp
0 Comments:
Post a Comment
<< Home