数组地址详解

#include <iostream>
using namespace std;

void main()
{
	int a[2][3] = {1,2,4, 6,8,10};

	cout<<"a:       "<<hex<<a<<endl;
	cout<<"&a[0]:   "<<hex<<&a[0]<<endl;
	cout<<"&a[1]:   "<<hex<<&a[1]<<endl;
	cout<<"a[0]:    "<<hex<<a[0]<<endl;
	cout<<"a[1]:    "<<hex<<a[1]<<endl;
	cout<<"a+1:     "<<hex<<a+1<<endl;
	cout<<"&a +1:   "<<hex<<&a +1<<endl;
	cout<<"&a[0]+1: "<<hex<<&a[0] + 1<<endl;

	cout<<"&a[0]:   "<<hex<<&a[0]<<endl;
	cout<<"&a[1]:   "<<hex<<&a[1]<<endl;
	cout<<"&a[0][0]:"<<hex<<&a[0][0]<<endl;
	cout<<"&a[0][1]:"<<hex<<&a[0][1]<<endl;
	cout<<"&a[0][2]:"<<hex<<&a[0][2]<<endl;
	cout<<"&a[1][0]:"<<hex<<&a[1][0]<<endl;
	cout<<"&a[1][1]:"<<hex<<&a[1][1]<<endl;
	cout<<"&a[1][2]:"<<hex<<&a[1][2]<<endl;


	cout<<*a<<endl;
	cout<<*a + 1<<endl;
	cout<<*(a+1)<<endl;
	cout<<*(a[1])<<endl;
	cout<<*(a[1]+1)<<endl;
	cout<<*a[0]<<endl;
	cout<<a<<endl;
	cout<<a + 1<<endl;
	cout<<**(a+1)+2<<endl;
	cout<<*(a+1)+2<<endl;
	cout<<(a+1)+2<<endl;

	unsigned char uc[10];
	unsigned long ul[10];
	cout<<&uc[0]<<endl;
	cout<<(&uc[0])+5<<endl;

	cout<<&ul[0]<<endl;
	cout<<(&ul[0])+5<<endl;

	system("pause");
}

  

原文地址:https://www.cnblogs.com/shanguanghui/p/3371468.html