I know what is pointer, but I always blurred by character pointer to string. Can you tell me these accordingly ? Thanks.
What is the difference ?
char string[] = "abc"; // between this one and
char * string = "abc";
How come ?
This one work
But this one print out weird characters.
Using std::string seems to be easier to manage but, what is the drawback of using std::string compare to char string[] ? Thanks.
What is the difference ?
char string[] = "abc"; // between this one and
char * string = "abc";
How come ?
This one work
Code:
const char * get()
{
return "xyz";
}
int main()
{
printf("%s",get());
return 0;
}
Code:
const char * get()
{
string str = "xyz";
return str.c_str();
}
int main()
{
printf("%s",get());
return 0;
}
Comment