// 数组的取值和地址.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>//操作符头文件
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
#pragma region 一维
int arrOneDimension[]={1,2,3,4,5,6,7,8,9};
for (int i = 0; i < 9; i++)
{
//cout<<arrOneDimension[i]<<" ";
cout<<*(arrOneDimension+i)<<" "<<&arrOneDimension[i]<<endl;//每个地址相差4个字节
}
cout<<endl;
#pragma endregion
#pragma region 二维
//int arrTwoDimensions[][3]={{1,3,6},{9,15,24},{39,63,102}};
int arrTwoDimensions[3][3]={1,3,6,9,15,24,39,63,102};
for (int i = 0; i < 3; i++)
{
cout<<endl<<*(arrTwoDimensions+i);//一维的一维的首地址 相差12字节
for (int j = 0; j < 3; j++)
{
//setw(int):设置域宽(下一个输出字符所占的总字符长度,右对齐)
//cout<<" "<<setw(4)<<*(*(arrTwoDimensions+i)+j)<<":"<<*(arrTwoDimensions+i)+j;//一维下的单个元素相差4字节
cout<<" "<<setw(4)<<arrTwoDimensions[i][j]<<":"<<&arrTwoDimensions[i][j];
}
}
cout<<endl;
#pragma endregion
getchar();
return 0;
}
源文件:http://pan.baidu.com/s/1eo3bK