#include <stdio.h>
int main()
{
char str[11] = "HelloWorld";
printf("%s\n",str);
printf("%s\n",str+3);
/* This Line here is the devil */
printf("%s\n",str[2]); // %s needs an addr not a value.
return 0;
}
为什么那条线会出现分段错误。是因为%s
inprintf
需要一个地址而不是一个值。真正的原因是什么??