Katakan kita mempunyai pembolehubah integer yang saiznya ialah 4 bait dan satu lagi pembolehubah penunjuk yang saiznya ialah 8 bait. Jadi apakah output di bawah?
#include<iostream> using namespace std; main() { int a[4][5][6]; int x = 0; int* a1 = &x; int** a2 = &a1; int*** a3 = &a2; cout << sizeof(a) << " " << sizeof(a1) << " " << sizeof(a2) << " " << sizeof(a3) << endl; cout << (char*)(&a1 + 1) - (char*)&a1 << " "; cout << (char*)(&a2 + 1) - (char*)&a2 << " "; cout << (char*)(&a3 + 1) - (char*)&a3 << " "; cout << (char*)(&a + 1) - (char*)&a << endl; cout << (char*)(a1 + 1) - (char*)a1 << " "; cout << (char*)(a2 + 1) - (char*)a2 << " "; cout << (char*)(a3 + 1) - (char*)a3 << " "; cout << (char*)(a + 1) - (char*)a << endl; cout << (char*)(&a[0][0][0] + 1) - (char*)&a[0][0][0] << " "; cout << (char*)(&a[0][0] + 1) - (char*)&a[0][0] << " "; cout << (char*)(&a[0] + 1) - (char*)&a[0] << " "; cout << (char*)(&a + 1) - (char*)&a << endl; cout << (a[0][0][0] + 1) - a[0][0][0] << " "; cout << (char*)(a[0][0] + 1) - (char*)a[0][0] << " "; cout << (char*)(a[0] + 1) - (char*)a[0] << " "; cout << (char*)(a + 1) - (char*)a; }
Untuk menyelesaikan masalah ini, kita boleh mengikuti beberapa perkara penting:
480 8 8 8 8 8 8 480 4 8 8 120 4 24 120 480 1 4 24 120
Atas ialah kandungan terperinci Teka-teki penunjuk C/C++?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!