为什么会异常?
代码如下:程序代码:
p = (int *)calloc(1000000, sizeof(int)); printf("%p\t%p\t%p\t%p\t%p\n", p, p + 1, p + 2, p + 3, p + 1000); //00000000009FD040 00000000009FD044 00000000009FD048 00000000009FD04C 00000000009FDFE0 scanf("%d\t%d\t%d\t%d\t%d", p, p + 1, p + 2, p + 3, p + 1000); //1 2 3 4 5 printf("%d\t%d\t%d\t%d\t%d", *p, *(p + 1), *(p + 2), *(p + 3), *(p + 1000)); //1 2 4 4 5 p = (int *)realloc(p, 2 * sizeof(int)); printf("%p\t%p\t%p\t%p\t%p\n", p, p + 1, p + 2, p + 3, p + 1000); //00000000009FD040 00000000009FD044 00000000009FD048 00000000009FD04C 00000000009FDFE0 printf("%d\t%d\t%d\t%d\t%d", *p, *(p + 1), *(p + 2), *(p + 3), *(p + 1000)); //1 2 3 4 5
当 将p + 1000改为 p + 10000时
程序代码:
//0000000000C0E040 0000000000C0E044 0000000000C0E048 0000000000C0E04C 0000000000C17C80 //1 2 3 4 5 //1 2 3 4 5 //0000000000C0E040 0000000000C0E044 0000000000C0E048 0000000000C0E04C 0000000000C17C80 //这一行输出异常, 直接结束程序
请问 为什么会发生上面的情况?