What are the different ways to define a string in the C language?
In C language, there are several ways to define a string.
- By using a character array, you can store a string by defining a character array, for example: char str[] = “Hello, World!”;
- By using character pointers, you can define a pointer that points to a string to store the string, like: char *str = “Hello, World!”;
- You can use a character pointer array to store strings, for example: char *str[] = {“Hello”, “World”};
- You can use character constants by directly using string constants in the program, such as “Hello, World!”.
- You can manipulate strings using the string library functions provided by the C language, such as strcpy and strcat.