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.
This function is used to return the reference to the element present at the position given as the parameter to the function.
array_name.at(position) Parameters: Position of the element to be fetched.
Return: It return the reference to the element at the given position.
Input: array_name1 = [1, 2, 3] array_name1.at(2); Output: 3 Input: array_name2 = ['a', 'b', 'c', 'd', 'e'] array_name2.at(4); Output: e
Element present at position 2: 3 Element present at position 4: e
Time Complexity: Constant i.e. O(1).
Given an array of integers, print integers in alternate fashion starting from 1st position.
Input: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Output: 2 4 6 8 10
2 4 6 8 10
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find the K closest points to origin using Priority Queue
- How to iterate through a Vector without using Iterators in C++
- Code Bloating in C++ with Examples
- Implementation of lower_bound and upper_bound on Set of Pairs in C++
- Implementation of lower_bound() and upper_bound() on Map of Pairs in C++
- std::cerr | Error Stream Object in C++ with Examples
- Methods vs. Functions in C++ with Examples
- basic_istream::readsome() in C++ with Examples
- std::is_function template in C++ with Examples
- type_traits::is_null_pointer in C++
- std::extent() template in C++ with Examples
- basic_istream::swap() in C++ with Examples
- basic_istream::peek() in C++ with Examples
- basic_istream::unget() in C++ with Examples
- exception::bad_exception in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.