What are the different ways to define a string in the C language?

In C language, there are several ways to define a string.

  1. By using a character array, you can store a string by defining a character array, for example: char str[] = “Hello, World!”;
  2. By using character pointers, you can define a pointer that points to a string to store the string, like: char *str = “Hello, World!”;
  3. You can use a character pointer array to store strings, for example: char *str[] = {“Hello”, “World”};
  4. You can use character constants by directly using string constants in the program, such as “Hello, World!”.
  5. You can manipulate strings using the string library functions provided by the C language, such as strcpy and strcat.
广告
Closing in 10 seconds
bannerAds