473,569 Members | 2,691 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 1020
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.ed u> 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.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 31 '05 #4
"Baloff" <wa****@wash.ed u> 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.ed u> 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
1342
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, 1) line. An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in test.exe Additional information: There is...
12
1876
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 physical memory located on a piece of custom hardware - this memory is only accessible using machine specific i/o so I want to hide all this in a...
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: template <typename type> class PhysMem { public:
5
1024
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 default grid color. How can I keep in memory the user selection ?
2
3221
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 text I apply the relevant style to it like so: With m_objselection .Style = strFormat .TypeText(strText) End With
2
1915
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 this point when the see the memory used by the program in task manager it is 135,654K. Now when I minimize the application the memory goes down to...
4
2028
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 copy of its functions held in memory (not sure what part of memory this would be refered to as). Then whenever an object has a function called on it...
4
1296
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, I want the table automatically show relevant rows and hide others. Say I type 10023,
0
2417
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 when I attempt to display the info in main anywhere the info is incorrect. I thought it might be a problem while I was reading the data in, but it...
0
3018
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 My site didnt get loaded and was stuck by displaying this error ., so plz anyone one give me a solution.,
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
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 we have to send another system
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.