By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,128 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,128 IT Pros & Developers. It's quick & easy.

memory selection

P: n/a

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
Jul 31 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.
Jul 31 '05 #2

P: n/a
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
Jul 31 '05 #3

P: n/a
On 01 Aug 2005 07:11:34 +1000, Baloff <wa****@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/~a...FAQ-acllc.html
Jul 31 '05 #4

P: n/a
"Baloff" <wa****@wash.edu> wrote in message news:87************@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?
Aug 1 '05 #5

P: n/a
Andrew Koenig wrote:
"Baloff" <wa****@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.

Aug 1 '05 #6

P: n/a
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!"
Aug 1 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.