1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| #include <iostream>
int show(int);
int a = 111; int b = 222; int c = 333; int* pp1[3]{&a, &b, &c};
decltype(pp1)* Fun1(int nNum);
typedef int int_array_t[3]; typedef int (*int_array_ptr_t)[3]; typedef int (*int_array_ptr_t2[3]);
int_array_t obj = {7, 8, 9}; int_array_ptr_t p_obj; int_array_ptr_t2* p_obj2 = &pp1;
int_array_t* fun0(int n); int_array_ptr_t fun1(int n); int_array_ptr_t2* fun3(int);
int main() {
int nNum = 6; int* p0 = &nNum;
std::cout << *p0 << std::endl;
int p1[3]{1, 2, 3};
int a = 1; int b = 2; int c = 3; int *p2[3]{&a, &b, &c};
std::cout << std::defaultfloat; std::cout << std::hex << std::showbase;
std::cout << "&a:\t" << (size_t)&a << std::endl; std::cout << "p3[0]:\t" << (size_t)p2[0] << std::endl;
std::cout << "&b:\t" << (size_t)&b << std::endl; std::cout << "p3[1]:\t" << (size_t)p2[1] << std::endl;
std::cout << "&c:\t" << (size_t)&c << std::endl; std::cout << "p3[2]:\t" << (size_t)p2[2] << std::endl;
std::cout << std::dec;
int(*p3)[3] = &p1; std::cout << (*p3)[0] << std::endl; std::cout << (*p3)[1] << std::endl; std::cout << (*p3)[2] << std::endl;
int** p4 = &p0; **p4 = 123456; std::cout << **p4 << std::endl;
int (*p5)(int) = show; p5(1); (*p5)(1);
int*(*p6(int))[3]; decltype(pp1)* pPP1 = Fun1(0); std::cout << *((int*)((*pPP1)[0])) << std::endl; std::cout << *((int*)((*pPP1)[1])) << std::endl; std::cout << *((int*)((*pPP1)[2])) << std::endl;
int_array_ptr_t2* pAray3 = fun3(0); std::cout << *((int*)((*pAray3)[0])) << std::endl; std::cout << *((int*)((*pAray3)[1])) << std::endl; std::cout << *((int*)((*pAray3)[2])) << std::endl;
int (*func[3])(int) = {show, show, show};
func[0](0); func[1](0); func[2](0); int (*(*func9)[3])(int) = &func; (*func9)[0](0); (*func9)[1](0); (*func9)[2](0); int(*(*func10)(int))[3] = fun1; int_array_ptr_t p10 = func10(0);
std::cout << (*p10)[0] << std::endl; std::cout << (*p10)[1] << std::endl; std::cout << (*p10)[2] << std::endl;
return 0; }
int show(int) { std::cout << "show function." << std::endl; return 0; }
decltype(pp1)* Fun1(int nNum) { return &pp1; }
int_array_t* fun0(int n) { p_obj = &obj; return &obj; }
int_array_ptr_t fun1(int n) { p_obj = fun0(n); return p_obj; }
int_array_ptr_t2* fun3(int) { return p_obj2; }
|