【发布时间】:2016-02-20 03:15:17
【问题描述】:
这里是 C 初学者,我有一个正在开发的程序,不幸的是,该程序要么没有正确读取数组,要么没有正确显示内容。
这就是我所拥有的
int main()
{
int size; // the number of elements
printf("Enter size of the array: \n");
scanf("%d", &size);
double *array = malloc(size*sizeof(int)); //memory allocated using malloc
if (array == NULL)
{
printf("Error! memory not allocated.");
exit(0);
}
printf("Enter elements of array: \n");
for (int i = 0; i<size; ++i)
{
scanf("%d", &array[i]);
}
printf("Results:");
double min = array[0];
printf("\nmin = %.3lf ", min);
double max = array[size - 1];
printf("\nmax = %.3lf", max);
这是我的输出
【问题讨论】:
-
您正在分配一个整数数组并将其分配给一个双指针。