r/cprogramming • u/Mediocre-Trainer-132 • Feb 26 '26
What's the best way to make a string variable?
I generally use:
char* string_variable = "text here";
But if there's a better way, let me know.
12
Upvotes
View all comments
23
u/bearheart Feb 26 '26
That's a pointer to a string literal, so correctly it should be
constqualified:const char* s = "foo";In fact, your compiler should generate a warning about this.