vector push_back() in C++

push_back(): It adds element at end of the vector. 

By this size of the vector increases by 1.

Parameter : 

data: Data to be adds at the end of the vector.

Syntax:

vecName.push_back(data)

For Example:

vec = {1,2,3,4}

vec.push_back(5)= > It adds 5 at end of the vector.

vec = {1.2.3.4.5}

Approach

C++

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

int main()
{
    vector<intvec = {1234};

    vec.push_back(5);

    for (int i = 0i < vec.size(); i++)
        cout << vec[i] << " ";
    return 0;
}


No comments:

Post a Comment