Question
How to declare a string variable in C?
Background
In my quest to learn the basics of c, I am trying to port on
Just put this line below, atop of your main()
function.
typedef string char*;
This allows you to create a string variable as you do with integers or characters in C. After that, your program should look like this:
#include
typedef char* string;
int main(void) {
string a = "Hello";
printf("%s\n", a); // %s format specifier for String
return 0;
}
For a live demonstration, visit this REPL.it.