array at() function in C++ STL Last Updated : 13 Jun, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The array::at() is a built-in function in C++ STL which returns a reference to the element present at location i in given array. Syntax: array_name.at(i) Parameters: The function accepts a single mandatory parameter i which specifies the location. Return value: The function returns an element present at index i in given array if i is valid index otherwise it throws out_of_range exception. Time Complexity: O(1) Below programs demonstrate the array::at() function: Program 1: CPP // CPP program to illustrate // the array::at() function #include <bits/stdc++.h> using namespace std; int main() { // array initialisation array<int, 5> arr = { 1, 5, 2, 4, 7 }; // prints the element at ith index // index starts from zero cout << "The element at index 2 is " << arr.at(2) << endl; return 0; } Output:The element at index 2 is 2 Program 2 : Illustrating function when it is implemented on lesser size array causing an error. CPP // CPP program to illustrate // the array::at() function #include <bits/stdc++.h> using namespace std; int main() { // array initialisation array<int, 5> arr = { 1, 5, 2, 4, 7 }; // it is an exception cout << "The element at index 7 is " << arr.at(7) << endl; return 0; } Output:Abort signal from abort(3) (SIGABRT) Comment More infoAdvertise with us Next Article Pass Array to Functions in C++ P pawan_asipu Follow Improve Article Tags : Misc C++ STL cpp-array CPP-Functions +1 More Practice Tags : CPPMiscSTL Similar Reads array get() function in C++ STL The array::get() is a built-in function in C++ STL which returns a reference to the i-th element of the array container. Syntax: get(array_name) Parameters: The function accepts two mandatory parameters which are described below. i - position of an element in the array, with 0 as the position of the 2 min read Pass Array to Functions in C++ In C++, a collection of elements stored in contiguous memory locations and having the same data type is called an array. Passing arrays to functions is done to perform various operations on array elements without messing up with the main code. In C++, an array can be passed in a function using a poi 5 min read array::at() in C++ STL Array classes are generally more efficient, light-weight and reliable than C-style arrays. The introduction of array class from C++11 has offered a better alternative for C-style arrays. array::at() This function is used to return the reference to the element present at the position given as the par 2 min read std::function in C++ The std::function() in C++ is a function wrapper class which can store and call any function or a callable object. In this article, we will learn about std::function in C++ and how to use it in different cases.Table of ContentWhat is std::function in C++?Example of std::functionMember Functions of s 5 min read copy_n() Function in C++ STL Copy_n() is the C++ function defined in <algorithm> library in STL. It helps to copy one array element to the new array. Copy_n function allows the freedom to choose how many elements must be copied in the destination container. This function takes 3 arguments, the source array name, the size 2 min read array::size() in C++ STL The array::size() method is used to find the number of elements in the array container. It is the member method std::array class defined inside <array> header file. In this article, we will learn about the array::size() method in C++.Example:C++// C++ Program to illustrate the use of array::si 2 min read Like