Q:

Error: Assign string to the char variable in C | Common C program Errors

0

Error: Assign string to the char variable in C | Common C program Errors

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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";

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now