944,017 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1023
  • C++ RSS
Nov 27th, 2007
0

C++ arrays

Expand Post »
what does the following do?

int array[6] = { 5, 3, 4, 17, 22, 19 };

int* ptr = array[0]
*ptr = -1;
thank you!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dsuh06 is offline Offline
15 posts
since Nov 2007
Nov 27th, 2007
0

Re: C++ arrays

The first line initializes the values of the array.
The second line is a syntax error. It should be int* ptr = &array[0]; The last line sets the value of te first array element to -1.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Nov 27th, 2007
0

Re: C++ arrays

wow thank you!

then in addition, what does

ptr+= 2
and ptr[1] =9

do?

thank you!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dsuh06 is offline Offline
15 posts
since Nov 2007
Nov 27th, 2007
0

Re: C++ arrays

>>then in addition, what does
Think about it and post your answer (or guess)
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Nov 27th, 2007
0

Re: C++ arrays

okies..

so this is what i thought:

ptr+= 2
increases the pointer by two.. so the ptr will now point to array[2]

and ptr[1] =9

the value of index 1 is equal to 9..

is this correct?

thank you!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dsuh06 is offline Offline
15 posts
since Nov 2007
Nov 27th, 2007
0

Re: C++ arrays

yes, but in the original array which element is set to 9?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Nov 28th, 2007
0

Re: C++ arrays

umm.. is it array[1] which is origially 3 set to 9?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dsuh06 is offline Offline
15 posts
since Nov 2007
Nov 28th, 2007
0

Re: C++ arrays

nope -- try again ?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: help....thx...
Next Thread in C++ Forum Timeline: Alternatives to arrays?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC