Search This Blog

Friday, February 4, 2011

Best programming practice: Constant usage in C/C++

Constant:

Constant means read-only. Answer is not complete but still good. Constant can be declared in various way for various needs.

const int a; //Constant (non-modifiable) integer
int const a; //Constant (non-modifiable) integer
const int *a; //pointer to a Constant (non-modifiable) integer
int * const a; //Constant (non-modifiable) pointer to a integer
int const * a const; //Constant (non-modifiable) pointer to constant integer

You can write a program without using a constant keyword which would work without any problem. But writing a program using constant is good practice and dictates user on how to use them based on its behavior.

No comments:

Post a Comment