References, Pointers and Constants
Simple C++ Data Types
const char *const int *
const double * char * &
int * &
double * & char * const
int * const
double * const
C++ Code | What It Means | When To Use It |
---|---|---|
char |
Single (scalar) value (character, integer, floating point number) |
To store data |
const char |
Constant value |
To declare a constant -- a value that cannot be changed |
char [] int [] |
Array (vector) of values |
To store the same type of data together |
const char [] |
Constant array of values |
To declare an array of constant values (no element in the array can be changed) |
char * |
Pointer to a single value or an array of values |
To store a string (char *) |
Pointer to a constant value |
When you don't want the value at the pointer to be changed, but you can still change the pointer |
|
char & |
Reference to a value |
To pass a value to a function which will be set by the function (without using a pointer) |
Reference to a pointer |
To pass a pointer to a function where the function will set the pointer (either by calling new or by assigning to the pointer |
|
Constant pointer |
When you want to point to a specific value. Allows to you to change the data that is pointed to, but you can't change the pointer |