473,505 Members | 14,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 31 '05 #1
6 1016
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
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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1341
by: MSNEWS | last post by:
I'm having problems using the word.applicationclass to load a word document. I've created this very simple code and I get the error below on the WordApp.Documents.Open("C:\temp\worddocs\1.doc", 0,...
12
1868
by: James Brown | last post by:
Hi all, Having problems designing a template-class. I'll describe my scenario first then show what I've come up with so far: Need a class to provide pointer/array-like access to an area of...
2
1287
by: James Brown | last post by:
Hi again, I'm referring back to my previous posting of the same title, with everyone's help I've now got a better understanding of what my goals are and I have a class which now looks like: ...
5
1023
by: Franck | last post by:
Hi, I'm addin javascript on some of my datagrid cells in the ItemCreatedEven which changes cell color on click (simulating selection). However, Postback event erase all selection and bring back...
2
3215
by: kayrogage | last post by:
I have an XML document that I am looping through to generate a word document. I loop through each element in the xml document and type it out in the word document, as I type out each element of...
2
1912
by: Asfar | last post by:
Hi, I have a VS2005 windows program written in c#. In this program I have an array list which stores many DataTable's. When I first run the pogram the arraylist is loaded with datatables. At...
4
2022
by: voidtwerp | last post by:
Hi, I hope this is not too OT but I would like clarification on how classes are held in memory. each object obviously has an individual copy of its data. I guess a class would only have one...
4
1292
by: Rob | last post by:
I want to implement a in-memory row selection function. Specifically, given a table Name Zip Phone Tony 98034 127xxxxx Mike 10023 271xxxx Jame 10023 253xxxx and a text box,...
0
2409
by: Hypnotik | last post by:
My program is to simulate cache memory. I read in the info from 2 external files, 1) access 2) data in memory. When I read the information in I display the info...and it is all correct. However...
0
3013
by: vjayis | last post by:
Hi i got an error while my site gets loaded Warning: mysql_query() : Unable to save result set in /path../includes/mysql.class.php on line 39 Error in Selection MySQL client ran out of memory...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.