What is Constant with example and How we use

Constants with example

ANSI C allows you to declare constants. When you declare a constant it is a bit like a variable declaration except the value cannot be changed.
The const keyword is to declare a constant, as shown below:
int const a = 1;
const int a = 2;
Note:
•    You can declare the const before or after the type. Choose one and stick to it.
•    It is usual to initialise a const with a value as it cannot get a value any other way.
The preprocessor #define is another more flexible method to define constants in a program.
You frequently see const declaration in function parameters. This says simply that the function is not going to change the value of the parameter.
The following function definition used concepts we have not met (see chapters on functions, strings, pointers, and standard libraries) but for completeness of this section it is included here:
void strcpy(char *buffer, char const *string)
The second argument string is a C string that will not be altered by the string copying standard library function.

Labels: