How do you define a string in the C language?

In C language, you can define strings using character arrays. For example:

char str[20]; // 定义一个长度为20的字符数组来存储字符串

Strings can also be defined using pointers. For example:

char *str = "Hello World"; // 定义一个指针,指向字符串常量"Hello World"

It is important to note that a string defined using a character array can be modified, while a string defined using a pointer is constant and cannot be directly changed. If you need to modify a pointer-defined string, you can use a character array for copying or dynamically allocate memory to store the string.

bannerAds