我正在学习C,做一些简单的例子,并发现了这种奇怪的行为.
当填充整数数组的元素时,如果任何元素设置为大于2147483647(我相信是最大整数值?),则数组中的其余元素将设置为该确切数字,每个其中之一.
我理解如果一个元素超出其类型限制,编译器会将其限制为该限制,但我无法理解为什么它与其他项目做同样的事情,甚至没有要求用户填充它们.
这是我运行的一个简单测试:
#include
using namespace std;
int main()
{
int test[5];
int num = 0;
for (int i=0; i<5; i++)
{
cout << "Enter the number in position " << i << endl;
cin >> num;
test[i] = num;
}
cout << "Values in the array: " <
for (int i=0; i<5; i++)
cout << test[i] << endl;
}
感谢您阅读,评论和帮助!