the const keyword creates a variable that can't be altered, i.e. has a fixed or constant value. In the case of a pointer it can create a pointer that can't be altered or a pointer to something that can't be altered.
-
const int PI1000 = 3141; /* Constant integer */
-
const int *pcInt = &PI1000; /* pointer to an integer that is constant, the pointer can be changed but the value of the integer it points to can't */
-
const int const *pcInt = &PI1000; /* Constant pointer to an integer that is constant, the pointer can't be changed and neither can the value of the integer it points */
-
int x;
-
int *pcInt = &x; /* Constant pointer to an integer, the pointer can't be changed but the value of the integer it points to can be changed */
-
The volatile keyword marks a variable about which the compiler can make no assumptions. This means that the compiler can not optomise uses of the variable. It would be used in the situation where you have a pointer to a memory location that could be changed outside the control of the main processor (say the receive register location of a UART).
I have mainly seen it used with pointers, so pointer to a volotile unsigned integer
volatile unsigned int *UART_RX_REGISTER;