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<int> vec = {1, 2, 3, 4};vec.push_back(5);for (int i = 0; i < vec.size(); i++)cout << vec[i] << " ";return 0;}
No comments:
Post a Comment