1a) There is this code
char *p;
p[0]='a';
p[1]='b';
printf("%s",p);
When i run this program on ideone.com compiler: c++ 4.3.2, it displays "RUNTIME ERROR" every single time i run it.
1b). however when i edit this code to
char *p;
//allocate memory using malloc
p[0]='a';
p[1]='b';
printf("%s",p);
It correctly runs and prints "ab" . shouldn't it require the p[2]='\0' at the end?
2)
char *p;
p="abc"
printf("%s",p);
this correctly runs and prints "abc" . why does this work without allocation.
Can anyone please explain the rules regarding string storage ?