• Popular Now

• 11
• 9
• 12
• 9
• 11

Archived

This topic is now archived and is closed to further replies.

Pointers?

This topic is 5191 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi all, i got a question about structure pointers, if i do something like this
struct movie
{
char title[50];
int year;
};

and in main i do this
movie amovie;
movie *pmovie;
pmovie = &amovie;

whats this good for? whenever i change pmovie,
pmovie->year = 1560;
i could have easily changed
amoiv.year = 1560;
its the same thing right? if thats the case, then why use the pointer shit there? [edited by - Mupp on February 6, 2004 8:07:55 AM]

Share on other sites
that is a great question..why use it there ?

that is absolutely useless......seriously...useless

"A soldier is a part of the 1% of the population that keeps the other 99% free" - Lt. Colonel Todd, 1/38th Infantry, Ft. Benning, GA

Share on other sites
Need clarification... are you asking what good a pointer is in your specific example, or what good pointers are in general?

Share on other sites
That sounds as a boring "introduction to pointers" example. Such examples are (for some reason) not often made to make sense, but to show the syntax of pointers. There are no point in using pointers like that, but there are uses, I assure you.

Share on other sites
Well.. i dont know really, could you tell me a few advantages with pointers? maybe point me to a better tutorial, or maybe just show me a short code example of a good use of pointers?

Share on other sites
One of the big uses of pointers in C++ is when you allocate memory on the run.

If you would like an array of integers, but don''t know how many when you compile the program, then you can use:
int* myArray = new int[x];

Or when creating objects. If you have a game engine, where you store all your objects in objectList, then you could do something like:

and so on..

Share on other sites
Further, when you have complex objects, passing a pointer to a function instead of the actual object will save your program from having to make a copy of that object first.

I use pointers all the time. (Maybe more than I should).