【发布时间】:2016-06-16 11:56:49
【问题描述】:
如果我输入数字 5,这个循环必须运行 5 次,但它运行了 6 次。问题是什么?
int main(){
int i, *arr, size;
printf("Please enter the Number: ");
scanf("%d ",&size);
arr = (int*) malloc(size * sizeof(int));
for(i = 0; i < size; i++){
scanf("%d ", &arr[i]);
}
}
【问题讨论】:
-
你在循环之前检查过size的值吗?
-
尝试在循环 scanf 中删除 %d 之后的空间。