realloc 动太内存分配报错问题
各位大神,下面的代码在VS 2015中报狂报错,而在DEV 中顺利编译,并打出正确结果,何解?#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
int num = 0;
scanf("%d", &num);
double *p = (double *)malloc(sizeof(double)*num);
printf("%x\n", p);
for (double i = 0.0; (int)i < num; (int)i++)
{
p[(int)i] = 1.1 + i;
printf("%f\n", p[(int)i]);
}
int newsize = 0;
scanf("%d", &newsize);
double *newp = (double *)realloc(p, sizeof(double)*newsize);
printf("%x\n", newp);
for (int i = 0; i < newsize; i++)
{
newp[i] = i + 1.2;
printf("%f\n", newp[i]);
}
free(p);
free(newp);
system("pause");
}
[附件ID:attach_1名称:C:\fakepath\505.png]