array get() function in C++ STL
array::get()
Syntax:
get" title="Rendered by QuickLaTeX.com" height="20" width="61" style="vertical-align: -1px;">(array_name)
Parameters:
- i – position of an element in the array, with 0 as the position of the first element.
- arr_name – an array container.
Return Value:
Time complexity:
Program 1:
// 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 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
Contact Us