![]() |
|
#1
|
|||
|
|||
Need help with dynamic arrays!I have to rewrite this program using dynamic arrays. I am having a difficult time understanding dynamic arrays. How might I do this? Here is the code any help at all is appreciated! Thank you
CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: Need help with dynamic arrays!!What is it you don't understand? Does your code work? If not, what's wrong with it?
|
|
#3
|
||||
|
||||
Re: Need help with dynamic arrays!!Since int aname[10] is really a pointer and you access the 4th element as aname[3] a dynamic array can be seen as the same thing.
aname = new int[10] loads a pointer into aname and the values can be accessed exactly the same way. IOW, int aname[10] loads the address of an array into the variable aname before the program starts, but aname = new int[10] loads the same pointer while the program runs. Just remember you need to free the dynamic array when finished with it. __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#4
|
|||
|
|||
Re: Need help with dynamic arrays!!yes it worked, but I added
CPP / C++ / C Code:
|
|
#5
|
||||
|
||||
Re: Need help with dynamic arrays!!Then you need to explain what's confusing you. Obviously what I said didn't make sense.
Quote:
__________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#6
|
|||
|
|||
Re: Need help with dynamic arrays!!I figure it out. I was confused about the difference between an array and a dynamic array. Thank you for the explaination! I got everything working properly.
|
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error in execution of 2D dynamic array | bobsta | C++ Forum | 4 | 19-Feb-2009 11:50 |
| Need Help with input files. | Efferus | C++ Forum | 2 | 24-Nov-2007 17:19 |
| Dynamic vs Static Arrays | WaltP | Miscellaneous Programming Forum | 5 | 16-Feb-2006 16:54 |
| Dynamic Arrays | swayp | C++ Forum | 2 | 27-Jan-2005 01:24 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The