data(): It is a build-in function in the STL library. It returns the pointer to the first element of the
vector.
Syntax:
dataType *pointer = vecName.data()
Parameters:
Their is no parameter requird for this funstion
File: stl_vector.h
For Example:
vec = {1,2,3,4,5}
*pointer = vec.data() => It points to the first element (i.e 1)
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){vector<int> vec = {1, 2, 3, 4, 5};int *it = vec.data();for (int i = 0; i < vec.size(); i++)cout << *it++ << " ";return 0;}
No comments:
Post a Comment