c++stl和std_C ++ STL数组容器– std :: array

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值