Run-Time Check Failure #2 - Stack around the variable 'A' was corrupted.
运行时检查失败#2-变量“A”周围的堆栈已损坏。
意思是:我用了A[10],实际只有A[9];
原先错误:
#include <stdio.h>
#define LEN 10
int main(int argc, char** argv)
{
int i, max, index = 0;
int arr[LEN] = {7, 2, 1, 3, 6, 9, 4, 10, 5, 8};
int *p = arr;
max = arr[0];
for (i = 0; i < LEN; ++i)
if (*(p + i) > max)//这里会导致p+i出现p往前走9次即p=arr[10]的数组越界
{
max = *(p + i);
index = i;
}
printf("max = arr[%d] = %d\n", index, max);
return 0;
}
改进办法:用++p优化流程。