pList[i] is the value of what in that memory address,
pList is the address of the first element,
&pList[i] is the address of that element number i however,
so pList+i is the address still as &pList[i]
Just explore them
Ab000dy_85
Junior Poster in Training
68 posts since Dec 2007
Reputation Points: 7
Solved Threads: 6
Skill Endorsements: 0
The code pName = &name should be either pName = name or pName = &name[0]. What you did was to take the address of the string which is already a pointer.
rubberman
Posting Maven
2,581 posts since Mar 2010
Reputation Points: 365
Solved Threads: 308
Skill Endorsements: 52
The code pName = &name should be either pName = name or pName = &name[0].
Actually pName = &name[0]; isn't valid, because you try to convert char* to string*.
Also
char* pColor = &color[10]; will do you no good, since &color[10] references some memory area that color itself doesn't have it. Since char color[]= "white"; is an array of characters of length 6 (including '\0'), &color[10] will point to a totally different memory area, and if printing, it might yeld odious results. If, say, you were to take something like this:
char* pColor = &color[2];
pColor will than point to the memory area of an array of chars starting from i, e.g. ite
Lucaci Andrew
Practically a Master Poster
649 posts since Jan 2012
Reputation Points: 91
Solved Threads: 91
Skill Endorsements: 12
after my changes I get the following output
Interger has a memory address 0x7fff5fbffac4
String has a memory address 0x7fff5fbffaa0
Array has a memory address 0x7fff5fbffa6c
Array has a memory address 0x7fff5fbffa70
Array has a memory address 0x7fff5fbffa74
Array has a memory address 0x7fff5fbffa74
Char has a memory address 0x7fff5fbffa80
Char has a memory address 0x7fff5fbffa88
Char has a memory address 0x7fff5fbffa90
Char has a memory address 0x7fff5fbffa98
Char has a memory address 0x7fff5fbffaa0
Double has a memory address 0x7fff5fbffa98
noting that as what Lucaci Andrew said "&color[10] will point to a totally different memory area" I changed it to &pColor+i to point to the first letter address
Ab000dy_85
Junior Poster in Training
68 posts since Dec 2007
Reputation Points: 7
Solved Threads: 6
Skill Endorsements: 0
Re Andrew's response - doh! Thanks! Brain fart there! Absolutely correct! I think I had just responded to a C query so brain was still in K&R mode, not E&S mode... :-) If I could vote down my previous post I would. :rolleyes:
From the department of excuses department: It was late when I read the post! I was tired! My glasses were dirty! Aren't all strings char* types? :lol:
rubberman
Posting Maven
2,581 posts since Mar 2010
Reputation Points: 365
Solved Threads: 308
Skill Endorsements: 52
Question Answered as of 3 Months Ago by
Ab000dy_85,
rubberman
and
Lucaci Andrew