C++ arrays

Reply

Join Date: Nov 2007
Posts: 15
Reputation: dsuh06 is an unknown quantity at this point 
Solved Threads: 0
dsuh06 dsuh06 is offline Offline
Newbie Poster

C++ arrays

 
0
  #1
Nov 27th, 2007
what does the following do?

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

int* ptr = array[0]
*ptr = -1;
thank you!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,152
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1437
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: C++ arrays

 
0
  #2
Nov 27th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 15
Reputation: dsuh06 is an unknown quantity at this point 
Solved Threads: 0
dsuh06 dsuh06 is offline Offline
Newbie Poster

Re: C++ arrays

 
0
  #3
Nov 27th, 2007
wow thank you!

then in addition, what does

ptr+= 2
and ptr[1] =9

do?

thank you!!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,152
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1437
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: C++ arrays

 
0
  #4
Nov 27th, 2007
>>then in addition, what does
Think about it and post your answer (or guess)
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 15
Reputation: dsuh06 is an unknown quantity at this point 
Solved Threads: 0
dsuh06 dsuh06 is offline Offline
Newbie Poster

Re: C++ arrays

 
0
  #5
Nov 27th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,152
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1437
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: C++ arrays

 
0
  #6
Nov 27th, 2007
yes, but in the original array which element is set to 9?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 15
Reputation: dsuh06 is an unknown quantity at this point 
Solved Threads: 0
dsuh06 dsuh06 is offline Offline
Newbie Poster

Re: C++ arrays

 
0
  #7
Nov 28th, 2007
umm.. is it array[1] which is origially 3 set to 9?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,152
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1437
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: C++ arrays

 
0
  #8
Nov 28th, 2007
nope -- try again ?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC