is it always necessary to initialize the const pointer to int at the declaration itself ??
Basically, yes. However, note the differences between intconst*, int *const, and intconst* const:
Which respectively denote
- an integer-constant pointer (i.e., a pointer to integer-constant)
- an integer pointer-constant (i.e., a constant pointer to integer)
- an integer-constant pointer-constant (i.e., a constant pointer to integer-constant).
given int* const, it is the pointer which is constant, not the pointed-to integer.
can you tell me where can anybody use this int * const??
Any time you don;t want a pointer changed.
A common use of this is when specifying a pointer as an argument to a function. Since a pointer is passed by value, changing the local copy of the pointer is usually a logic error. Declaring the pointer argument as const prevents this.