[英]What will happen when i try to add one more value compared to the specified size of array in c++?
#include <iostream>
using namespace std;
int main()
{
int marks[4]={40,10,25,56};
marks[5]=99;
}
What will happen if i tried to add 5th element in array of size 4?如果我尝试在大小为 4 的数组中添加第 5 个元素会发生什么?
Not really an answer, but this shows how to use std::array
instead of a raw array:不是真正的答案,但这显示了如何使用
std::array
而不是原始数组:
#include <iostream>
#include <array>
using namespace std;
int main()
{
// int marks[4] = { 40,10,25,56 };
std::array<int, 4> marks = { 40,10,25,56 };
marks[5] = 99;
}
Depending on your platform and tools, debug builds show an error message when you access such an array out of bounds.根据您的平台和工具,当您越界访问此类数组时,调试版本会显示错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.