array::data()
C++ STL में array::data() फंक्शन सरणी के पहले तत्व को इंगित करने वाला पॉइंटर लौटाता है।
सिंटैक्स
array_name.data();
पैरामीटर
कोई पैरामीटर नहीं।
रिटर्न प्रकार
पहले तत्व का पॉइंटर।
उदाहरण 1: पहला तत्व एक्सेस करें
#include <bits/stdc++.h>
using namespace std;
int main() {
array 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;
}
आउटपुट
The array elements are: 45.2 89.6 99.1 76.1 The first element is: 45.2
उदाहरण 2: पॉइंटर अंकगणित से अन्य तत्व एक्सेस करें
auto it = percentage.data(); it++; cout << "\nThe second element is: " << *it; it++; cout << "\nThe third element is: " << *it;
आउटपुट
The second element is: 89.6 The third element is: 99.1