Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > memory selection

Reply
Thread Tools

memory selection

 
 
Tobias Blomkvist
Guest
Posts: n/a
 
      07-31-2005
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.
 
Reply With Quote
 
 
 
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      07-31-2005
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
 
Reply With Quote
 
 
 
 
Baloff
Guest
Posts: n/a
 
      07-31-2005

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
 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      07-31-2005
On 01 Aug 2005 07:11:34 +1000, Baloff <> 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
 
Reply With Quote
 
Andrew Koenig
Guest
Posts: n/a
 
      08-01-2005
"Baloff" <> wrote in message news:...

> 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?


 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      08-01-2005
Andrew Koenig wrote:
> "Baloff" <> 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.

 
Reply With Quote
 
Artie Gold
Guest
Posts: n/a
 
      08-01-2005
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!"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
selection structure nested within another selection structure 4Ankit@gmail.com Javascript 1 12-07-2006 11:47 AM
JTable with row selection, but no cell selection Simon Niederberger Java 2 01-07-2005 04:17 PM
JS comparing innerHTML to text selection (window.getSelection() /document.selection) Andrew Crowe HTML 1 09-13-2004 02:22 PM
How to change a range selection to text selection? Loebb Javascript 0 02-23-2004 02:12 PM
HOWTO autopost the selection list upon selection curiousity ASP .Net Mobile 0 11-21-2003 12:57 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57