在C语言中,可以使用strcpy函数来对字符数组整体赋值。strcpy函数的声明在string.h头文件中,它的原型如下:
char* strcpy(char* destination, const char* source);
其中,destination表示目标字符数组,source表示源字符数组。下面是一个例子:
#include#include int main() { char source[] = "Hello, World!"; char destination[20]; strcpy(destination, source); printf("Destination string: %s\n", destination); return 0; }
输出结果为:
Destination string: Hello, World!
在这个例子中,source数组存储了字符串"Hello, World!",destination数组是一个空数组。然后,使用strcpy函数将source数组的内容复制到destination数组中,使得destination数组也存储了相同的字符串。最后,使用printf函数输出destination数组的内容,即可看到赋值结果。