How to Read C++ Variable Declarations


C++ variable declarations can be extremely complex. There is a specific process to follow in order to read them correctly:

  1. Start at the variable name.
  2. Read the first item to the right of the variable name (if there is one). If the item is a right parenthesis, go to the next step.
  3. Read the first item to the left of the variable name (if there is one). If the item is a left parenthesis, go to the next step.
  4. Read the next item to the right of the variable name (if there is one). If the item is a right parenthesis, go to the next step.
  5. Read the next item to the left of the variable name (if there is one). If the item is a left parenthesis, go to the next step.
  6. Repeat Steps 4 and 5 until you run out of items to read. Usually you will run out of items to the right of the variable name well before you run out of items to the left.

The items you will most frequently encounter in a C++ variable declaration are summarized in the following table:

Item Appears Read
int, double, Date, etc. to the left of the variable name exactly as it appears
const to the left of the variable name as "constant"
* to the left of the variable name as "pointer to"
& to the left of the variable name as "reference to"
( to the left of the variable name not read, skip to next step
[] To the right of the variable name "array of"
[6] To the right of the variable name as "array of 6" (or whatever number appears inside the brackets)
[][10] To the right of the variable name as "two-dimensional array of an unknown number of rows with 10 columns of" (or whatever number appears inside the brackets)
[4][10] To the right of the variable name as "two-dimensional array of 4 rows with 10 columns of" (or whatever numbers appear inside the brackets)
) to the right of the variable name not read, skip to next step