OOPortal OOPortal
Pointers/Memory Allocation   «Prev  Next»
Lesson 17

C++ Memory Allocation Conclusion

In this module you learned:
  1. How to create const pointer arguments to functions
  2. How to create aliases for variables using reference declarations
  3. How C++ implements call-by-reference using reference declaration
  4. How to use a generic pointer type
  5. How to use new and delete to manipulate free store memory
  6. How to create dynamically allocated multidimensional arrays
When declaring a variable, the type given is the type of any expression which looks like the declaration.
Thus, if we have the declarations

int a, *b, c[], *(*d[])(); 

then, in the code, the expressions a, *b, c[] and *(*d[])() would all evaluate to an integer. Encountering this declaration one might find it challenging figuring out that d is an array of pointers to functions which return integer pointers, but you do know what type it will evaluate to when used in the context given.
Thus you know that the statement
a = *(*d[5])(x, y) 
will place an integer in a, even if you are not sure what happened.
You could similarly match types by stripping off matching levels of indirections:
b = (*d[5])(x, y) 

would store an integer pointer in b rather than the value of the integer.

Pointers Memory Allocation - Quiz

Click the Quiz link below to take a multiple-choice quiz covering the topics presented in this module.
Pointers Memory Allocation - Quiz