const
and constexpr
are not interchangeable, in your case you do not want to drop the const
but you want to add constexpr
like so:
constexpr const char* hello()
{
return "hello world";
}
The warning you receive when you drop const
, is because a string literal is an array of n const char
and so a pointer to a string literal should be a *const char ** but in C a string literal is an array of char even though it is undefined behavior to attempt to modify them it was kept around for backwards compatibility but is depreciated so it should be avoided.