Here I've two lines of code
const char * s1 = "test";
char s2 [] = "test";
Both lines of code have the same behavior, so I cannot see any difference whether I should prefer s1 over s2 or vice-versa. In addition to s1 and s2, there is also the way of using std::string. I think the way of using std::string is the most elegant. While looking at other code, I often see that people either use const char * or char s []. Thus, my question is now, when should I use const char * s1 or char s [] or std::string? What are the differences and in which situations should I use which approach?
"abc"is 'array of const char', i.e.const char[N](N is the size of the string including the null terminator). This is true for both C and C++ at least right now. To add to Kos's comment right above, string literals have 'static storage duration'(last for the duration of the program). As the standard or this answer quotes.