| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Baloff" |
| Date: |
31 Jul 2005 04:11:34 PM |
| Object: |
memory selection |
Hello
why is it that the lower index in an array occupies the highest
number address. e.g.
#include <iostream>
using namespace std;
int main() {
int a[10];
cout << "sizeof(int) = "<< sizeof(int) << endl;
for(int i = 0; i < 10; i++)
cout << "&a[" << i << "] = "
<< (long)&a[i] << endl;
}
sizeof(int) = 4
&a[0] = -1073743552 why not start 3516
&a[1] = -1073743548
&a[2] = -1073743544
&a[3] = -1073743540
&a[4] = -1073743536
&a[5] = -1073743532
&a[6] = -1073743528
&a[7] = -1073743524
&a[8] = -1073743520
&a[9] = -1073743516 and ends with 3552
where the numbers located on the physical drive relative to each other?
thanks
.
|
|
| User: "Andrew Koenig" |
|
| Title: Re: memory selection |
31 Jul 2005 11:29:26 PM |
|
|
"Baloff" <washdc@wash.edu> wrote in message news:877jf61y0p.fsf@wash.edu...
why is it that the lower index in an array occupies the highest
number address. e.g.
....
&a[0] = -1073743552 why not start 3516
&a[1] = -1073743548
&a[2] = -1073743544
&a[3] = -1073743540
&a[4] = -1073743536
&a[5] = -1073743532
&a[6] = -1073743528
&a[7] = -1073743524
&a[8] = -1073743520
&a[9] = -1073743516 and ends with 3552
Since when is -1073743552 greater than -1073743516?
.
|
|
|
| User: "Old Wolf" |
|
| Title: Re: memory selection |
31 Jul 2005 11:46:03 PM |
|
|
Andrew Koenig wrote:
"Baloff" <washdc@wash.edu> wrote:
why is it that the lower index in an array occupies the highest
number address. e.g.
&a[0] = -1073743552 why not start 3516
&a[9] = -1073743516 and ends with 3552
Since when is -1073743552 greater than -1073743516?
I have absolutely no idea.
.
|
|
|
|
|
| User: "Tobias Blomkvist" |
|
| Title: Re: memory selection |
31 Jul 2005 04:00:17 PM |
|
|
Baloff sade:
Hello
why is it that the lower index in an array occupies the highest
number address. e.g.
The stack usually grows downward.
Tobias
--
IMPORTANT: The contents of this email and attachments are confidential
and may be subject to legal privilege and/or protected by copyright.
Copying or communicating any part of it to others is prohibited and may
be unlawful.
.
|
|
|
|
| User: "Artie Gold" |
|
| Title: Re: memory selection |
31 Jul 2005 11:56:03 PM |
|
|
Baloff wrote:
Hello
why is it that the lower index in an array occupies the highest
number address. e.g.
#include <iostream>
using namespace std;
int main() {
int a[10];
cout << "sizeof(int) = "<< sizeof(int) << endl;
for(int i = 0; i < 10; i++)
cout << "&a[" << i << "] = "
<< (long)&a[i] << endl;
ITYM
<< &a[i] << endl;
Or the not-quite-right:
<< (unsigned long)&a[i] << endl;
}
sizeof(int) = 4
&a[0] = -1073743552 why not start 3516
&a[1] = -1073743548
&a[2] = -1073743544
&a[3] = -1073743540
&a[4] = -1073743536
&a[5] = -1073743532
&a[6] = -1073743528
&a[7] = -1073743524
&a[8] = -1073743520
&a[9] = -1073743516 and ends with 3552
where the numbers located on the physical drive relative to each other?
`Physical drive'? What's *that*?
HTH,
--ag
--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
.
|
|
|
|
| User: "=?ISO-8859-15?Q?Juli=E1n?= Albo" |
|
| Title: Re: memory selection |
31 Jul 2005 04:04:12 PM |
|
|
Baloff wrote:
why is it that the lower index in an array occupies the highest
number address. e.g.
Do you know negative numbers?
--
Salu2
.
|
|
|
|
| User: "Jack Klein" |
|
| Title: Re: memory selection |
31 Jul 2005 05:32:03 PM |
|
|
On 01 Aug 2005 07:11:34 +1000, Baloff <washdc@wash.edu> wrote in
comp.lang.c++:
Hello
why is it that the lower index in an array occupies the highest
number address. e.g.
#include <iostream>
using namespace std;
int main() {
int a[10];
cout << "sizeof(int) = "<< sizeof(int) << endl;
for(int i = 0; i < 10; i++)
cout << "&a[" << i << "] = "
<< (long)&a[i] << endl;
^^^^^^^^^^^
Change this to (unsigned long)&a[1] and prepare to be thrilled and
delighted.
}
sizeof(int) = 4
&a[0] = -1073743552 why not start 3516
&a[1] = -1073743548
&a[2] = -1073743544
&a[3] = -1073743540
&a[4] = -1073743536
&a[5] = -1073743532
&a[6] = -1073743528
&a[7] = -1073743524
&a[8] = -1073743520
&a[9] = -1073743516 and ends with 3552
where the numbers located on the physical drive relative to each other?
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.
|
|
|
|

|
Related Articles |
|
|