操作未分配内存的字符串指针的奇怪结果
程序代码:
#include <stdio.h>
#include <math.h>
int main()
{
int i=0;
char *n;
n = "this is !";
printf("%s\n", n);
while (i < 10)
{
sprintf(n, "; call function %s : %d", "_mas", i);
printf("%d:%p:%s:%d\n", i++, n, n, strlen(n));
}
return 0;
}
输出:
程序代码:this is ! 0:00407030:; call function _mas : 0:24 1:00407030::0 2:00407030::0 3:00407030::0 4:00407030::0 5:00407030::0 6:00407030::0 7:00407030::0 8:00407030::0 9:00407030::0
为什么第一次执行成功而后面却无法进行?
缓冲区的地址没变,那么谁覆盖了缓冲区?








