Home » C++ STL

array::back() function with Example in C++ STL

C++ STL | array::back() function: Here, we are going to learn about the back() function of Array in C++ STL.
Submitted by IncludeHelp, on February 28, 2019

C++ STL array::back() function

back() function is a library function of array and it is used to get the last element of an array, it returns the reference to the last element in an array.

Syntax:

    array_name.back();

Parameters: None

Return value: It returns a reference to the last element of array_name.

Example:

    Input or array declaration:
    array<int,5> values {10, 20, 30, 40, 50};

    Function call:
    values.back();

    Output:
    50

C++ STL program to get the last element of an array using array:back()

#include <array>
#include <iostream>
using namespace std;

int main()
{
	array<int,5> values {10, 20, 30, 40, 50};
    
	//printing first element
	cout<<"Last element is: "<<values.back()<<endl;

	return 0;
}

Output

Last element is: 50





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.