PointersThe topic of pointers and dynamic memory management is not understood by many folks for a couple of reasons :

One, Lets face it..It requires some effort to understand whats going on. However it is a one time effort and subsequently one can learn as one experiments, codes etc. Then why don't folks put in the one time effort.
Second reason, I can surmise is  : Most of the C++ introductory books have one chapter or at most two on pointers before diving in to OOPS concepts. OOPs principles are important and they should be covered but often times, the understanding of pointers is sometimes assumed or swept under the carpet when the aspects of dynamic memory management are introduced such as virtual  function, cloning, copy constructor, new etc.

So, the programmer typically has some idea of pointers and tries to piece together the OOPs concepts. This is ok if the programmer  never has to deal with memory in his working life, i mean, if a Virtual machine does all the work for him/her. So, you see the point here, the evolution of modern languages like Java, .NET frameworks gives a programmer a lot of stuff for free but what is lost is the basic understanding of memory management. Thus a programmer might use an for(i=0;i<10;i++) { for (j=0;j<10;j++) cout<<"RK[i][j]"<<endl;}} and might think that the data is being stored as a 10*10 cell matrix or some thing like that. He might not be able to appreciate the fact that all 100 values in the array are stored as contiguous memory locations and RK declared as an array is nothing but a label to the memory address. He might not appreciate the fact that the same result of the above loop can be obtained by a pointer to the first element of the array.

In most of the OOPs concepts in C++, there is an inevitable meeting with symbols such as *, &, -> and they make a code really fast.Crucial concepts like pass by reference, operator overloading, rule of three, virtual functions, etc are all dependent on the prior knowledge of pointers. However for folks who have not spent time on pointers , they cannot appreciate the beauty of some of the rules that need to be followed. One might have a vague idea of heap and stack , but when one sees an error related to memory thrown by the machine, it is a time to go back to fundamentals .

Well , when I began coding C++, I underwent the same cycle, coded and learnt from some introductory books, knew the scott meyer tips and applied them in my code , but pointers was an area which I was shaky about. until…I was suggested a book on pointers which was well suited to a guy who already had coded in c++. my understanding of C++ was greatly enhanced by a book titled "C++ Pointers and Dynamic Memory Management" by Michael C.Daconta. 

If a programmer wants to develop some real power applications, I guess this is one of books which gives a clear description of the pointers business. Well, it is 400 page book and if you are a person who loves to critique your own code, you can pretty much cover the book over a weekend and when you start coding , the next time on, you will be raring to use pointers as they are indeed what makes C++ powerful.

Advertisements