2009年4月14日 星期二

Point

 
How to pass one point to get point value in function.

void GetCharPoint( char * p)
{
 char *temp = "abcdefghij";
 p = new char [11];
 //remember the last is '\0'.(temp[10] = '\0')
 memcpy(p,temp,11);
}
// p = NULL;

void GetCharPoint( char ** p)
{
 char *temp = "abcdefghij";
//this is not the memcpy(p, temp, 11) , but the memcpy(*p, temp, 11);
 *p = new char [11];
 memcpy(*p,temp,11);
}
// p Ok.

void GetCharPointRef(char *&p)
{
 char *temp = "abcdefghij";
 p = new char [11];
 memcpy(p,temp,11);
}
// p Ok.

沒有留言:

張貼留言