C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 17th, 2010, 11:33 AM
sethra sethra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Posts: 10 sethra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 49 m 7 sec
Reputation Power: 0
Adress values of each element of an array

Hello,

a) I wonder the address values of each element of an array.
Does str[0] have a lower address than str[1]?

b) I have created an array to test this:

Code:
char str[] = "This Is A Test.";


When i printed the following line in a for loop:

Code:
for(int i = 0; i<15; i++) cout << &str[i] << endl;


I got this result:

Code:
This Is A Test.
his Is A Test.
is Is A Test.
s Is A Test.
 Is A Test.
Is A Test.
s A Test.
 A Test.
A Test.
 Test.
Test.
est.
st.
t.
.


I expected to see hexadecimal address values
Thanks is advance for all the replies

Reply With Quote
  #2  
Old March 17th, 2010, 03:21 PM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,936 Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 h 12 m 42 sec
Reputation Power: 1312
It should work if you cast it to void *. cout << x is overloaded differently for char * and other pointers: for the former, it prints the string x points to, and for the latter, it prints the address (i. e., literally the value of x as a pointer).

I could also answer your real concern ("I wonder the address values of each element of an array. Does str[0] have a lower address than str[1]?"), but you're so close to discovering the answer yourself, so I won't.

Reply With Quote
  #3  
Old March 18th, 2010, 04:14 AM
sethra sethra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Posts: 10 sethra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 49 m 7 sec
Reputation Power: 0
Thanks. That did the trick. Different overloading of cout << x is something I should dig in some time.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Adress values of each element of an array

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap