Home »
C programs »
C common errors programs
Error: Assign string to the char variable in C | Common C program Errors
Here, we will learn how and what an error or warning occurs, when we assign string to the character variable in C?
By IncludeHelp Last updated : March 10, 2024
Error: Assign string to the char variable in C
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:
Example
#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 name[]="Amit shukla";
C Common Errors Programs »