home > resources > c++ coding standard > online version

Pointer Variables

  • Pointers should be prepended with 'p'.
  • Place the * close to the variable name not the pointer type.


  • The idea is that the difference between a pointer, object, and a reference to an object is important for understanding the code, especially in C++ where -> can be overloaded, and casting and copy semantics are important.
  • The * belongs near the variable name since its not cumulative to other declarations of the same line. This convention follows closely the way c++ behaves in this matter.

    Example 2-7. Placement of * during pointer declarations

    BAD:  int* p_var;
    GOOD: int *p_var;

Example 2-8. Pointer Variables Example

QString *p_name = new QString;
QString *p_name; // note, only pName is a pointer.
QString name;
QString address;