array get() function in C++ STL Last Updated : 29 Aug, 2018 Comments Improve Suggest changes 1 Likes Like Report 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< i >(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 first element. arr_name - an array container. Return Value: The function returns a reference to the element at the specified position in the array Time complexity: O(1) Below programs illustrate the above function: Program 1: CPP // CPP program to demonstrate the // array::get() function #include <bits/stdc++.h> using namespace std; int main() { // array initialisation array<int, 3> arr = { 10, 20, 30 }; // function call cout << "arr[0] = " << get<0>(arr) << "\n"; cout << "arr[1] = " << get<1>(arr) << "\n"; cout << "arr[2] = " << get<2>(arr) << "\n"; return 0; } Output: arr[0] = 10 arr[1] = 20 arr[2] = 30 Program 2: CPP // CPP program to demonstrate the // array::get() function #include <bits/stdc++.h> using namespace std; int main() { // array initialisation array<char, 3> arr = { 'a', 'b', 'c' }; // function call cout << "arr[0] = " << get<0>(arr) << "\n"; cout << "arr[1] = " << get<1>(arr) << "\n"; cout << "arr[2] = " << get<2>(arr) << "\n"; return 0; } Output: arr[0] = a arr[1] = b arr[2] = c Create Quiz Comment P pawan_asipu Follow 1 Improve P pawan_asipu Follow 1 Improve Article Tags : Misc C++ STL cpp-array CPP-Functions +1 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like