string back() in C++

back(): It returns a read/write reference to the data at the last element of the string.

Parameters: No parameters are required for this function.

Syntax:

str.back()

For Example:

str = "abc"

str.back() => It returns reference to last character of the string (i.e c)

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string str = "abc";
    cout << str.back() << "\n";

    return 0;
}


No comments:

Post a Comment