举例说明:

1)int* p[2] 是一个指向int型的指针数组,即:p是包含两个元素的指针数组,指针指向的是int型。

可以这样来用:

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int main(int argc, char* argv[])
 6 
 7 {
 8 
 9     int* p[2];
10 
11     int a[3] = {1, 2, 3};
12 
13     int b[4] = {4, 5, 6, 7};
14 
15     p[0] = a;
16 
17     p[1] = b;
18 
19     int i;
20     cout << "output the first:" <<endl;
21     for(i = 0; i < 3; i++){
22 
23         cout << *p[0] + i << endl;// cout << **p + i;
24         cout << **p + i << endl;
25         cout << "*p:" << *p << endl;
26         cout << "&*p" << &*p << endl;
27         cout << "p:" << p << endl;
28         cout << "&p:" << &p << endl;
29     }
30 
31     cout << "output the second:" <<endl;
32 
33     for(i = 0; i < 4; i++){
34 
35         cout << *p[1] + i << endl;//not equal cout << **p + i;
36         
37         cout << p << endl;//the same af
38 
39         cout << &p << endl;//the same bf
40     }
41     return 0;
42 
43 }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2021-08-18
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2021-06-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
相关资源
相似解决方案