|
Beginners to C++ programming find the concept of pointers foreign to them. Pointers, and code that manipulates pointers (aka pointer arithmetic), can even be daunting to some of the most seasoned programmers. Pointers in C++ account for a fair share of bugs in programs due to the lack of understanding. So why even use them? Well, besides being the most problematic, they are also some of the most powerful features in the language. Handy pointers for using pointers.
|
|
|
|
|
My Computer Science professor liked to carry around a briefcase and point to it while saying "pointer to the handle."
|
|
|
|
|
Bob Dole The internet is a great way to get on the net.
2.0.82.7292 SP6a
|
|
|
|
|
I've asked this question during interviews. Usually Java programmers are really confused... I don't understand why some schools would teach Java instead of C/C++? Obviously C is the language of real programmers...
Ok enough rant-ing and onto the question:
1. Copying by values vs copying by reference. Obviously passing a pointer to something is much more efficient than doing actual deep copy.
2. All high level languages do is hide the pointers from you, but anytime you index an array pointer arithmetic is being done in the background. Back in the day the stl containers were not available and pointer arithmetic was being used as a iterator of sorts. It still can be used to deconstruct binary memory into objects (perhaps when accessing shared memory created by an application written in some arcane language).
3. Function pointers can be used to simulate polymorphic behavior in a procedural language (like C or Fortran).
4. Most important in my mind is the fact that if you understand pointers and memory, you'll be able to write better code. You'll be able to do your own memory management which could be more efficient.
|
|
|
|
|
VentsyV wrote: I don't understand why some schools would teach Java instead of C/C++?
Because when they last started evaluating their language of choice for CS101 it looked like Java was going to conquer the world. In another 5-10 years I expect to see JavaScript take over. Perhaps more importantly it sidestepped the epic holywar between adherents of the MSVC++ and GCC compilers. When I was a freshman ('99); the net result of this was that the "official" compiler for intro C++ classes was Borlands. In all but one of my more advanced C++ classes we were allowed to use the compiler of our choice as long as it was specified; the exception was my OS class where the binaries we had to use for all the parts of the OS that we weren't writing fill in the function code for were only available on via the Universities Slowlaris shell server.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|