অ্যারে হল একই ডেটা টাইপের উপাদানগুলোর সমষ্টি যা কনটিনিউয়াস মেমরি লোকেশনে সংরক্ষিত থাকে।
C++ স্ট্যান্ডার্ড লাইব্রেরিতে অ্যারের কাজকর্ম সাপোর্ট করার অনেক লাইব্রেরি রয়েছে। 그중 একটি হল array::data() মেথড।
C++-এ array::data() অবজেক্টের প্রথম উপাদানকে নির্দেশকারী একটি পয়েন্টার রিটার্ন করে।
সিনট্যাক্স
array_name.data();
প্যারামিটার
এই ফাংশন কোনো প্যারামিটার গ্রহণ করে না।
রিটার্ন টাইপ
অ্যারের প্রথম উপাদানকে নির্দেশকারী একটি পয়েন্টার।
উদাহরণ
Array Data() মেথডের ব্যবহার ব্যাখ্যা করার প্রোগ্রাম −
#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;
}
আউটপুট
The array elements are: 45.2 89.6 99.1 76.1 The first element is: 45.2
উদাহরণ
Array Data() মেথডের ব্যবহার ব্যাখ্যা করার প্রোগ্রাম
#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;
}
আউটপুট
The array elements are: 45.2 89.6 99.1 76.1 The second element is: 89.6 The third element is: 99.1