I got a _CrtIsValidHeapPointer error with my code. And I finally find out what caused the trouble.
I use the example below to illustrate it:
char* c=(char*)malloc(20*sizeof(char));
//cout<<&c<<endl;
c="hello world";
//cout<<&c<<endl; //if you uncomment the 2 clauses,you'll see the address is the same
//which means the string literal is in the heap
cout<<c<<endl;
free(c);
1) It seemed that spaces used by string literals can't be freed? Why?
2)What't the method do you use to assign valee to array of char?
ps: I use sprintf(c,"hello world");
that works fine. But any better way?
After read the answers. I realize that I misunderstand the meaning of &c.
I should use printf("%p\n",c);
instead.