I will give some examples. Maybe this will make some people easier:
Spaces have no meaning in any of them, so I put them everywhere to avoid ambiguity.
const char * & bar
bar not const, *bar is const (this also means bar[0] , etc.). If you change bar , it will now point to new memory (for example, a new array), but the old data will remain unchanged.
char const * & bar
as stated above.
char * const & bar
bar now const (you cannot change it to point to another memory), but the memory itself ( *bar ) can be changed
const char * const & bar
bar and *bar are constants. You cannot change anything.
char * & const bar
This is mistake.
The code you found uses the first form (in fact) to return a const char array. The caller is not allowed to pass char* ; it must be const char* , so if the caller does not discard constness (which is bad), they will not change the memory. This means that the function can safely return a pointer to internal data, knowing that it will not be changed.
source share