Code:
#include "stdio.h"
#include "string.h"
int main()
{
char *p = "abc";
printf("p is %s
", 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
",p);
return 0;
}
Output:
Segmentation fault (core dumped)
Could someone explain why this happens?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…