
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Array data() in C++ STL with Examples
The array is a collection of elements of the same data type stored in continuous memory locations.
C++ standard library contains many libraries that support the functioning of arrays. One of them is an array data() method.
The array data() in c++ returns a pointer pointing to the first element of the object.
Syntax
array_name.data();
Parameter
There are no parameters accepted by the function.
Return type
A pointer to the first element of the array.
Example
Program To Illustrate The Use Of Array Data() Method −
#include <bits/stdc++.h> using namespace std; int main(){ array<float, 4> percentage = { 45.2, 89.6, 99.1, 76.1 }; cout << "The array elements are: "; for (auto it = percentage.begin(); it != percentage.end(); it++) cout << *it << " "; auto it = percentage.data(); cout << "\nThe first element is:" << *it; return 0; }
Output
The array elements are: 45.2 89.6 99.1 76.1 The first element is:45.2
Example
Program To Illustrate The Use Of Array Data() Method
#include <bits/stdc++.h> using namespace std; int main(){ array<float, 4> percentage = { 45.2, 89.6, 99.1, 76.1 }; cout << "The array elements are: "; for (auto it = percentage.begin(); it != percentage.end(); it++) cout << *it << " "; auto it = percentage.data(); it++; cout << "\nThe second element is: " << *it; it++; cout << "\nThe third element is: " << *it; return 0; }
Output
The array elements are: 45.2 89.6 99.1 76.1 The second element is: 89.6 The third element is: 99.1
- Related Questions & Answers
- forward_list max_size() in C++ STL with Examples
- multiset size() in C++ STL with Examples
- multiset max_size() in C++ STL with Examples
- multiset upper_bound() in C++ STL with Examples
- multiset lower_bound() in C++ STL with Examples
- jQuery data() with Examples
- Array.BinarySearch(Array, Object) Method with examples in C#
- Array algorithms in C++ STL
- Array sum in C++ STL
- Working with Array and Vectors using STL in C++
- Array product in C++ using STL
- Array get() function in C++ STL?
- array at() function in C++ STL
- Array.BinarySearch(Array, Int32, Int32, Object) Method with examples in C#
- Array::crbegin() and array::crend() in C++ STL?
Advertisements