Constness of an object (i.e. non-reference) parameter matters, and it doesn't matter depending on context. Both examples declare the same function, so in that regard constness of a parameter is ignored.
This applies to pointers and non-pointers equally. These sets declare exactly one function each:
void foo(int);
void foo(int const); // const normally applies to left
void foo(const int); // const is first token of type, so it applies to right
void bar(T*);
void bar(T* const);
void baz(T const *);
void baz(T const * const);
void baz(const T *);
void baz(const T * const);
Note that T const *
is not a const qualified T *
. It is a non-const qualified type; a non-const pointer to const T.
But if you declare the parameter as const in the function definition, then you cannot modify the parameter. So, in this case constness matters. Whether the parameter is modified or not doesn't matter to the caller because the parameter is a copy of the argument that the caller has no way to access. Example:
void foo(int x) {
x++; // OK
void foo(int const) {
x++; // Not OK
Or 'ptr' is always copy?
Yes. An object (i.e. non-reference) parameter is always a copy. In some cases that copy may be elided by the optimiser when that's more efficient.
Or it might help to optymise compiled code?
Quite unlikely.
Currently I can only see that it prevent from any pointers arithmetic
Constness won't prevent pointer arithmetic. Example:
void fun(T* const param) {
T* next = param + 1;
Being void*
does prevent pointer arithmetic unless you convert to another pointer type.