If you assign a string to the character variable, it may cause a warning or error (in some of the compilers) or segmentation fault error occurs.
如果将字符串分配给字符变量,则可能会导致警告或错误(在某些编译器中)或发生分段错误。
Consider the code:
考虑一下代码:
#include <stdio.h>
int main(void) {
char name="Amit shukla";
printf("%s",name);
return 0;
}
Output
输出量
Segmentation fault
How to fix?
怎么修?
Declare character array instead of char variable to assign string
声明字符数组而不是char变量来分配字符串
char name[]="Amit shukla";
翻译自: https://www.includehelp.com/c-programs/assign-string-to-the-char-variable-in-c.aspx