In C++, std::array::front() returns the first element of a std::array. It is the same element as index 0.
It returns a reference, so you can read it or replace it. Like back(), it needs an array with at least one element. Include <array> to use it.
This is a member of std::array<T, N>, not of a plain C array and not of std::vector. A std::array has a fixed size N that is part of its type, and it lives on the stack like a normal variable.
Syntax
Call front with empty brackets. It takes no arguments.
C++
nums.front();
nums.front() = 50;
Call
What it does
nums.front()
Reads the first element.
nums.front() = 50
Replaces the first element with a new value.
The last element has a matching function: back().
Library declarations
C++
reference front();
const_reference front() const;
Parameters
Parameter
Description
None
front() takes no parameters. Call it with empty brackets.
Return Value
Return Value
Description
Reference
A reference to the first element, which is the same as nums[0].