#include <iostream> using namespace std; int main() { int a[3] = {1, 2, 3}; cout << *(a) << std::endl; cout << *(a+ 1) << std::endl; cout << *(a + 2) << std::endl; cout << *(&a[0] + 0) << std::endl; cout << *(&a[0] + 1) << std::endl; cout << *(&a[0] + 2) << std::endl; int addr = (int)a;//直接用地址操作 cout << *(int*)addr << endl; cout << *(int*)(addr+ 4) << endl; cout << *(int*)(addr+8) << endl; getchar(); return 0; //可以看出数组名a的值就是&a[0],代表了第一个元素的首地址,+1直接访问下一个元素的 }
时间: 2024-11-05 14:40:48