Vector Front Function - C++ Programming Tutorial
C++ Course / STL Vector / Vector Front Function

Vector Front Function

BLUF: Mastering Vector Front Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Vector Front Function

C++ is renowned for its efficiency. Learn how Vector Front Function enables low-level control and high-performance computing in the tutorial below.

C++ Vector front

It provides a reference to the initial element of the vector.

Syntax

Consider a vector.Syntax would be:

Example

v.front();

Parameter

This function does not contain any parameter.

Return value

This function retrieves the initial element from the vector.

Example 1

Let's see a simple example.

Example

#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<string>  language{"java","C","C++"};
cout<<language.front();
return 0; 
}

Output:

In this instance, the front method showcases the initial element of the language object.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience