Home »
        C++ STL
    
    array::front() function with Example in C++ STL
    
    
    
    
    
        C++ STL | array::front() function: Here, we are going to learn about the front() function of Array in C++ STL.
        
            Submitted by IncludeHelp, on February 28, 2019
        
    
    
    C++ STL array::front() function
    font() function is a library function of array and it is used to get the first element of an array, it returns the reference to the first element in an array.
    Syntax
    array_name.front();
    Parameter(s)
    None
    
    Return value
    It returns a reference to the first element of array_name.
    
    Sample Input and Output
Input or array declaration:
array<int,5> values {10, 20, 30, 40, 50};
Function call:
values.front();
Output:
10
    Example
    C++ STL program to get the first element of an array using array:front() −
#include <array>
#include <iostream>
using namespace std;
int main() {
  array<int, 5> values{10, 20, 30, 40, 50};
  // printing first element
  cout << "First element is: " << values.front() << endl;
  return 0;
}
Output
First element is: 10
    
    
  
    Advertisement
    
    
    
  
  
    Advertisement