belongs to collection: C Common Errors Programs
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 name[]="Amit shukla";
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Consider the code:
Output
How to fix?
Declare character array instead of char variable to assign string
need an explanation for this answer? contact us directly to get an explanation for this answer