Hi,
please see this code
This code works fine and the out put isCode:#include <iostream> using namespace std; int main(void) { char *pA=new char[10]="Raj"; char *pB; cout<<pA<<endl; pB=new char[10]; char *q = pB; while(*pB++ = *pA++); *pB = '\0'; cout<<q<<endl; return 0; }
Raj
Raj
string copy happens correctly.
(I am running this code in .NET 2005).
But if I change a little like below the code is giving exception.
please clarify.Code:#include <iostream> using namespace std; int main(void) { char *pA=new char[10]="Raj"; char *pB; cout<<pA<<endl; pB=new char[10]= "aaa"; // This is the changed line char *q = pB; while(*pB++ = *pA++); *pB = '\0'; cout<<q<<endl; return 0; }




Reply With Quote