Array address problems

Source: Internet
Author: User

Int _ tmain (INT argc, _ tchar * argv [])

{

Int ints [10] = {

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

};

Int * IP = ints + 3;

}

Q:

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

& Amp; 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

The above is the result printed by the machine. The source code is:

#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;}

My machine is a 32-bit machine and the compiling environment is vs2005.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.