array data() in C++ STL with Examples Last Updated : 23 Jul, 2018 Comments Improve Suggest changes 4 Likes Like Report The array::data() is a built-in function in C++ STL which returns an pointer pointing to the first element in the array object. Syntax: array_name.data() Parameters: The function does not accept any parameters. Return Value: The function returns an pointer. Below programs illustrate the above function: Program 1: CPP // CPP program to demonstrate the // array::data() function #include <bits/stdc++.h> using namespace std; int main() { array<int, 5> arr = { 1, 2, 3, 4, 5 }; // prints the array elements cout << "The array elements are: "; for (auto it = arr.begin(); it != arr.end(); it++) cout << *it << " "; // Points to the first element auto it = arr.data(); cout << "\nThe first element is:" << *it; return 0; } Output: The array elements are: 1 2 3 4 5 The first element is:1 Program 2: CPP // CPP program to demonstrate the // array::data() function #include <bits/stdc++.h> using namespace std; int main() { array<int, 5> arr = { 1, 2, 3, 4, 5 }; // prints the array elements cout << "The array elements are: "; for (auto it = arr.begin(); it != arr.end(); it++) cout << *it << " "; // Points to the first element auto it = arr.data(); // increment it++; cout << "\nThe second element is: " << *it; // increment it++; cout << "\nThe third element is: " << *it; return 0; } Output: The array elements are: 1 2 3 4 5 The second element is: 2 The third element is: 3 Create Quiz Comment G gopaldave Follow 4 Improve G gopaldave Follow 4 Improve Article Tags : Misc C++ STL cpp-array Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like