关于数组地址的问题

int _tmain(int argc, _TCHAR* argv[])

{

    int ints[10]={

       10,20,30,40,50,60,70,80,90,100

    };

    int *ip=ints+3;

}

问:

ints = 0012FF3C

ints[4] =  50

ints+4 = 0012FF4C

*ints+4 = 14

*(ints+4) = 50

ints[-2] = -858993460

&ints =  0012FF3C

&ints[4] = 0012FF4C

&ints[-2] = 0012FF34

ip = 0012FF48

ip[4] =  80

ip+4 = 0012FF58

*(ip+4) = 80

ip[-2] = 20

&ip = 0012FF30

&ip[4] = 0012FF58

&ip+4 = 0012FF40

&ip[-2] =  0012FF40

 

&ints[ 0]=0012FF3C     ints[ 0]=10

&ints[ 1]=0012FF40     ints[ 1]=20

&ints[ 2]=0012FF44     ints[ 2]=30

&ints[ 3]=0012FF48     ints[ 3]=40

&ints[ 4]=0012FF4C     ints[ 4]=50

&ints[ 5]=0012FF50     ints[ 5]=60

&ints[ 6]=0012FF54     ints[ 6]=70

&ints[ 7]=0012FF58     ints[ 7]=80

&ints[ 8]=0012FF5C     ints[ 8]=90

&ints[ 9]=0012FF60     ints[ 9]=100

 

&ip[-3]=0012FF3C       &ip+(-3)=0012FF24      ip[-3]=10             ip+-3=0012FF3C       *(ip+-3) =10

&ip[-2]=0012FF40       &ip+(-2)=0012FF28       ip[-2]=20             ip+-2=0012FF40        *(ip+-2)=20

&ip[-1]=0012FF44       &ip+(-1)=0012FF2C      ip[-1]=30             ip+-1=0012FF44       *(ip+-1) =30

&ip[ 0]=0012FF48       &ip+( 0)=0012FF30       ip[0]=40             ip+ 0=0012FF48       *(ip+ 0) =40

&ip[ 1]=0012FF4C       &ip+( 1)=0012FF34       ip[1]=50             ip+ 1=0012FF4C       *(ip+ 1) =50

&ip[ 2]=0012FF50       &ip+( 2)=0012FF38       ip[2]=60             ip+ 2=0012FF50       *(ip+ 2) =60

&ip[ 3]=0012FF54       &ip+( 3)=0012FF3C       ip[3]=70             ip+ 3=0012FF54       *(ip+ 3) =70

&ip[ 4]=0012FF58       &ip+( 4)=0012FF40       ip[4]=80             ip+ 4=0012FF58       *(ip+ 4) =80

&ip[ 5]=0012FF5C       &ip+( 5)=0012FF44       ip[5]=90             ip+ 5=0012FF5C        *(ip+5) =90

&ip[ 6]=0012FF60       &ip+( 6)=0012FF48       ip[6]=100            ip+ 6=0012FF60        *(ip+6) =100

&ip[ 7]=0012FF64       &ip+( 7)=0012FF4C       ip[7]=-858993460     ip+ 7=0012FF64        *(ip+7) =-858993460

&ip[ 8]=0012FF68       &ip+( 8)=0012FF50       ip[8]=1245112        ip+ 8=0012FF68       *(ip+ 8) =1245112

&ip[ 9]=0012FF6C       &ip+( 9)=0012FF54       ip[9]=4269494        ip+ 9=0012FF6C       *(ip+ 9) =4269494


上面是机器打印的结果,源码为:

#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	int ints[10]={
		10,20,30,40,50,60,70,80,90,100
	};
	int *ip=ints+3;

	cout<<"ints ="<<setw(20)<<ints<<endl;
	cout<<"ints[4] ="<<setw(20)<<ints[4]<<endl;
	cout<<"ints+4 ="<<setw(20)<<ints+4<<endl;
	cout<<"*ints+4 ="<<setw(20)<<*ints+4<<endl;
	cout<<"*(ints+4) ="<<setw(20)<<*(ints+4)<<endl;
	cout<<"ints[-2] ="<<setw(20)<<ints[-2]<<endl;
	cout<<"&ints ="<<setw(20)<<&ints<<endl;
	cout<<"&ints[4] ="<<setw(20)<<&ints[4]<<endl;
	cout<<"&ints[-2] ="<<setw(20)<<&ints[-2]<<endl;


	cout<<"ip ="<<setw(20)<<ip<<endl;
	cout<<"ip[4] ="<<setw(20)<<ip[4]<<endl;
	cout<<"ip+4 ="<<setw(20)<<ip+4<<endl;
	cout<<"*(ip+4) ="<<setw(20)<<*(ip+4)<<endl;
	cout<<"ip[-2] ="<<setw(20)<<ip[-2]<<endl;
	cout<<"&ip ="<<setw(20)<<&ip<<endl;
	cout<<"&ip[4] ="<<setw(20)<<&ip[4]<<endl;
	cout<<"&ip+4 ="<<setw(20)<<&ip+4<<endl;
	cout<<"&ip[-2] ="<<setw(20)<<&ip[-2]<<endl;
	

	for (int i=0;i<10;i++)
	{
		cout<<"&ints["<<setw(2)<<i<<"]="<<&ints[i]<<"	";
		cout<<"ints["<<setw(2)<<i<<"]="<<ints[i]<<endl;
	}
	for (int i=-3;i<10;i++)
	{
		cout<<"&ip["<<setw(2)<<i<<"]="<<(&ip[i])<<"	";
		cout<<"&ip+("<<setw(2)<<i<<")="<<(&ip+i)<<"	";
		cout<<"ip["<<setw(2)<<i<<"]="<<(ip[i])<<"	";
		cout<<"ip+"<<setw(2)<<i<<"="<<(ip+i)<<"	";
		cout<<"*(ip+"<<setw(2)<<i<<") ="<<(*(ip+i))<<endl;
	}
	system("pause");
	return 0;
}
本人机器是32位机,编译环境VS2005.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值