指出以下代码的输出结果:
#include <stdio.h>
#include <string.h>
int main()
{
char a;
char *str = &a;
strcpy(str, "hello");
printf(str);
return 0;
}
答案是Segmentation fault
使用 strcpy, strcat, sprintf, strcmp, strcasecmp 等字符串操作函数内存访问越界时会发生段错误
近期评论