This code produces \"p = hello world\":
#include \"stdio.h\"
#include \"string.h\"
int main(){
char *p;
p=\"hello world\";
printf(\"p is %s \\n\",p)
There are two distinct parts to memory copying. The first is the memory occupied by the item you want to copy (which you create in your example using the malloc() function), and the second is a pointer to that block of memory (which you call p). These two entities must be set up for the destination too, before you can do a copy. In your first example that fails, you have not set up the memory block for the destination (but it has been set for the source implicitly when you declare the string hello
).