   Pointers?
  Hi all, i got a question about structure pointers, if i do something like thisstruct movie{   char title[50];   int year;};  and in main i do thismovie 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]
  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 ;  Need clarification... are you asking what good a pointer is in your specific example, or what good pointers are in general? ;  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. ;  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? ;  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:objectList.Add(new MyClass());and so on.. ;  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). ;  If we''re talking about C, then pointers are the only way.But in C++ applications, pointers shouldn''t be used very often. For example, using a Standard Library container such as vector or list is strongly preferred to dynamically allocating an array. Furthermore, references are safer than pointers because references are guaranteed to point to a valid object, yet they offer the same performance benefits. So, only where implementing the internals of certain classes or interfacing with code written in other languages should you use pointers in C++.