LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-11-2010, 11:21 AM   #1
vbx_wx
Member
 
Registered: Feb 2010
Posts: 181

Rep: Reputation: 16
adresses in array


Code:
	int main()
{
	double numbers[10] = {0.0,1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9};
	double* nPtr = &numbers[0];

	cout << numbers << endl;
	cout << nPtr + 1 << endl;
	cout << nPtr + 2 << endl;
	cout << nPtr + 3 << endl;
	cout << nPtr + 4 << endl;
	cout << nPtr + 5 << endl;
	cout << nPtr + 6 << endl;
	cout << nPtr + 7 << endl;
	cout << nPtr + 8 << endl;
	cout << nPtr + 9 << endl;

}
OUTPUT:
Code:
0xbf92e408
0xbf92e410
0xbf92e418
0xbf92e420
0xbf92e428
0xbf92e430
0xbf92e438
0xbf92e440
0xbf92e448
0xbf92e450
I am confuse why my memory adresses are not from 8 to 8 bytes. Can someone explain why ? Thank you
 
Old 11-11-2010, 11:30 AM   #2
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Rep: Reputation: 49
Quote:
Originally Posted by vbx_wx View Post
... why my memory adresses are not from 8 to 8 bytes.
If by 'from 8 to 8 bytes' you mean what I think you mean, they are. I.e. each line's number is the previous plus 8.
 
Old 11-11-2010, 07:47 PM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Remember the address is printed in hexadecimal format (base 16) so the addresses are each 8 bytes long and are on zero or eight byte boundaries.
 
Old 11-12-2010, 11:05 PM   #4
lesca
Member
 
Registered: Sep 2010
Posts: 56

Rep: Reputation: 0
The size of double is 8 byes.

The output base is 16, digits are from 0 to 9 and a to f.

0x00 + 0x08 = 0x08 (8 in Dec)
0x08 + 0x08 = 0x10 (16 in Dec)

Hope my explanation may help you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 NICS, 2 IP adresses.... howto? derekn Linux - Networking 1 11-03-2004 02:55 PM
what is my ns3 ; ns2 adresses murat1 Linux - Networking 1 04-21-2004 03:26 PM
Network IP Adresses greggery Linux - General 1 12-01-2003 03:30 PM
CUPS and network adresses ionmich Slackware 1 09-27-2003 12:38 PM
How do I forward IP Adresses? teeno Linux - Networking 2 07-16-2001 09:38 AM


All times are GMT -5. The time now is 04:49 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration