배열 연속 메모리 위치에 저장된 동일한 데이터 유형의 요소 모음입니다.
C++ 표준 라이브러리에는 배열의 기능을 지원하는 많은 라이브러리가 포함되어 있습니다. 그 중 하나가 배열 data() 메서드입니다.
C++의 배열 data()는 객체의 첫 번째 요소를 가리키는 포인터를 반환합니다.
구문
array_name.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