C++ Vector data() function
Last Updated : 17 Mar 2025
This function returns a pointer to an array internally used by a vector to store its elements.
Syntax
Consider a vector 'v' and pointer 'p'. Syntax would be:
Parameter
It does not contain any parameter.
Return value
It returns a pointer to an array.
Example 1
Let's see a simple example.
Output:
In this example, k is the pointer of integer type referring to the elements of a vector.
Example 2
Let's see a simple another example.
Output:
In this example, k is the pointer of string type referring to the elements of a vector v.