"No man can serve the two masters God and mammon, for then he will love the one and hate the other or be loyal to the one and despise the other."


POINTERS USAGE IN C++: BEGINNERS TO ADVANCED




Table of Contents


General Introduction

Chapter 1.    Introduction: Objective, Target Audience and Article Revisons


Part 1: Introduction to Pointers in C++

Chapter 2.    The & and * Operators
Chapter 3.    Pointers: A First Example
Chapter 4.    Arrays of Pointers


Part 2: Dynamic Memory Allocation and Linkage with Arrays

Chapter 5.    Dynamic Allocation Of Memory: Single Dimension Pointers
Chapter 6.    Linkages between Array And Pointer Syntax in C++
Chapter 7.    Multi-Dimensional Pointers
Chapter 8.    Using Pointers to Return Values From Functions
Chapter 9.    Dynamic Memory Allocation: Multi-Dimensional Pointers


Part 3: Function Pointers and Deciphering (Long) Pointer Declarations

Chapter 10.   Beginning with Function Pointers
Chapter 11.   Deciphering (Long) Pointer Declarations
Chapter 12.   Function Pointers and typedef


Chapter 1: Introduction: Objective, Target Audience and Article Revisons
C++ is a programming language that includes features of both low-level and high-level programming languages. It allows direct access to memory address locations but also provides advanced objext-oriented programming capabilities. It is also backward compatible with C. The flexibility that C++ provides comes with enormous complexity. My purpose in this article is to demystify the complexity that creeps into C++ from pointers. Personally, once I had understood pointers in-depth, learning the rest of what is necessary to be learnt in C++ was very easy.

The article is targetted at beginners and intermediate users of C++. However, it can be helpful to anyone who wants to test his knowledge of pointer syntax in C++. Especially, the chapters, "Chapter 11: Deciphering (Long) Pointer Declarations" and "Chapter 9: Dynamic Memory Allocation: Multi-Dimensional Pointers" would be very useful.

I have made two major changes since the previous version of the article. C++ syntax is now colour-coded through images and a couple of illustrations have been added to make examples easier to understand. The entire article uses more than a dozen examples to illustrate core concepts. It helps to practice these examples yourself as you read along. The source code is included with the download version. All examples have been tested with GNU C++ compiler v3.4.

Please send your suggestions on improving the article and making necessary corrections at varunhome@gmail.com. You can also find some more tips on my webpage at http://www.geocities.com/varunhostel. Follow the link labelled 'Technical Articles'.



Last updated: 15-Aug-2005. Available from: http://www.geocities.com/varunhostel
© 2005 Varun Sud (varunhome@gmail.com)
1