Google News
logo
Embedded C - Interview Questions
When should we use const in a C program?
There are the following places where we need to use the const keyword in the programs.
 
* In case of call by reference, if you don’t want to change the value of the passed variable. ex:
int PrintData ( const char *pcMessage);
* In some places, const is better than macro because const is handled by the compiler and has a type checking.

* In the case of the I/O and memory-mapped register, const is used with the volatile qualifier for efficient access. for ex:
const volatile uint32_t *DEVICE_STATUS = (uint32_t *) 0x80102040;
* When you don’t want to change the value of an initialized variable.
Advertisement