![](https://img-blog.csdnimg.cn/img_convert/7cb3a601c4bf448d05a623805a35b8d8.png)
c++stl和std
Here you will learn about STL Array Container in C++ i.e. std::array.
在这里,您将了解C ++中的STL数组容器,即std :: array。
I Hope you know about C-type arrays (arrays in C language). Since C++ is just extension to C language we can use those. The main property is that, Array contains series of elements of same type placed in contiguous memory locations. i.e suppose we have marks of 100 students, instead of declaring 100 variables, using array the 100 int values can store in contiguous memory locations and all can be accessed through same identifier, by just adding some number to identifier which points to particular index.
我希望您了解C型数组(C语言数组)。 由于C ++只是C语言的扩展,因此我们可以使用它们。 主要特性是,Array包含一系列放置在连续内存位置中的相同类型的元素。 也就是说,假设我们有100个学生的分数,而不是声明100个变量,而是使用数组将100个int值存储在连续的内存位置中,并且可以通过在标识符上添加一些数字(指向特定索引)来通过相同的标识符进行访问。
Declaring Normal Array
声明法线数组
Syntax: type arrayName[size];
语法:类型arrayName [size];
Example: int marks[5]; //This is array of type int which stores marks of 5 students
示例: int标记[5]; //这是int类型的数组,其中存储5个学生的分数
Initializing Arrays
初始化数组
int marks [5] = { 10, 23, 15, 20, 25 };
整数标记[5] = {10,23,15,20,25};
This stores the elements in contiguous locations, that in index 0, element 10 will be stored remaining follows as same.
这会将元素存储在连续的位置,即在索引0中将存储元素10,其余部分相同。
Accessing the elements of the array:
访问 数组 的 元素 :
Syntax: arrayName[index];
语法: arrayName [index];
Example: marks[2]; //This will gives the value of the element at 2nd index of the array marks, which is 15.
示例: marks [2]; //这将在数组标记的第二个索引处给出元素的值,即15。
If we try to access giving a number which is greater than size of the array in place of index, it will raise an error called arrayIndexOutof bound error.
如果我们尝试访问给定的数字,该数字大于数组的大小(而不是索引的位置),它将引发一个名为arrayIndexOutof的错误。
These are directly implem