#include<string.h>
#include<stdio.h>
int main()
{
char *p;
strcpy(p,"hello world");
}
Well,Does it show undefined behaviour or Does it point to hello world? I have seen many of the programmers using these kind of sytax.I know its better than an array where you dont know the size of string.But is it good to use in the programming.can anyone explain it?
That is undefined behavior as
pis uninitialized. I don’t imagine you actually see a lot of people doing that…strcopyexpects a buffer of sufficient length to copy the contents of the second argument into. Your example is purposely contrived, but in real code you would need to know the size ofsource_stringin order to allocate the buffer.