Hey can anyone tell what this const means here???Code:void put_data(const TRAY *ptr);
Printable View
Hey can anyone tell what this const means here???Code:void put_data(const TRAY *ptr);
It's basically for the internals of the function. A const, as you (hopefully) know, cannot be changed.
That does not mean you have to submit a const variable -- it means that the function will not alter the ptr. You can submit a plain TRAY*, it will be "converted" to a const TRAY* automatically.
A lot of standard library functions are written this way so that, as EVOEx points out, the user can tell from the prototype that the submitted pointer will be treated as const.
So you mean const is used only for the safeside of the pointer inside a function.
So it can be omitted also,not strictly required,right??
So whether const can be used with other datatypes also other than pointers??
const can be used with any data type.
You should always make your functions const-correct for safety & code clarity.
If you don't intend on changing the value of a variable, make it const.
It's particularly important to pointer arguments though. You want functions that take pointer arguments to use const when they do not modify the value pointed to so that a const pointer could be passed to them as an alternative to a non const pointer. const correctness with local variables is less important.