首先直接上代码:
#include <iostream >
using namespace std;
int* getnums() {
int* p = new int[8];
*p = 0;
*(p + 1) = 1;
*(p + 2) = 2;
*(p + 3) = 3;
return p;
}
void display(int** ptr) {
std::cout <<"*ptr="<< *ptr << std::endl;
std::cout <<"**ptr="<< **ptr << std::endl;
std::cout << "*(*ptr + 1)="<<*(*ptr + 1) << std::endl;
int* p = *ptr;
for (int i = 0; i < 4; i++) {
std::cout << *(p + i) << std::endl;
}
}
int main()
{
int* myfeats[4];
for (int i = 0; i < 4; i++) {
myfeats[i] = getnums();
}
display(myfeats);
return 0;
}
输出的结果如下:
*ptr=000001E24D1EEBF0
**ptr=0
*(*ptr + 1)=1
0
1
2
3