Consider:
int testfunc1 (const int a) { return a; } int testfunc2 (int const a) { return a; }
Are these two functions the same in every aspect or is there a difference?
I’m interested in an answer for the C language, but if there is something interesting in the C++ language, I’d like to know as well.
const TandT constare identical. With pointer types it becomes more complicated:const char*is a pointer to a constantcharchar const*is a pointer to a constantcharchar* constis a constant pointer to a (mutable)charIn other words, (1) and (2) are identical. The only way of making the pointer (rather than the pointee)
constis to use a suffix-const.This is why many people prefer to always put
constto the right side of the type (“East const” style): it makes its location relative to the type consistent and easy to remember (it also anecdotally seems to make it easier to teach to beginners).