Skip to content
Related Articles

Related Articles

valarray end() function in C++
  • Last Updated : 24 Oct, 2018

The end() function is defined in valarray header file. This function returns an iterator pointing to the past-the-end element in the valarray v.

Syntax:

template< class T > 
    end( valarray<T>& v );

Parameter: This function takes a mandatory parameter v which represents the valarray object.

Returns: This function returns the iterator to the past-the-end in the valarray.

Below programs illustrate the above function:



Example 1:-




// C++ program to demonstrate
// example of end() function.
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // Initializing valarray
    valarray<int> varr = { 10, 20, 30, 40, 50 };
  
    cout << "valarray contains=";
  
    for (auto i = begin(varr); i != end(varr); i++) {
        cout << ' ' << *i;
    }
  
    cout << endl;
  
    return 0;
}
Output:
valarray contains= 10 20 30 40 50

Example 2:-




// C++ program to demonstrate
// example of end() function.
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // Initializing valarray
    valarray<int> varr = { -10, -20, -30, -40 };
  
    cout << "valarray contains=";
  
    for (auto i = begin(varr); i != end(varr); i++) {
        cout << ' ' << *i;
    }
  
    cout << endl;
  
    return 0;
}
Output:
valarray contains= -10 -20 -30 -40
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :