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
Show parent comment
1
u/Snatchematician Feb 27 '26
I would have thought that char* s = “foo” gives you a null terminated string (so s[3] is 0) while char s[] = “foo” gives you an array of chars (so s[3] is undefined).
I don’t know C so this might be wrong.