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?