Code:
#include "stdio.h"
#include "string.h"
int main()
{
char *p = "abc";
printf("p is %s \n", p);
return 0;
}
Output:
p is abc
Code:
#include "stdio.h"
#include "string.h"
int main()
{
char *p = "abc";
strcpy(p, "def");
printf("p is %s \n",p);
return 0;
}
Output:
Segmentation fault (core dumped)
Could someone explain why this happens?