Why does this generate errors?
char variable = "\n";
printf ("%c",variable);
But changing the double quotes to single fixes it?
char variable = '\n';
printf ("%c",variable);
Why does this generate errors?
char variable = "\n";
printf ("%c",variable);
But changing the double quotes to single fixes it?
char variable = '\n';
printf ("%c",variable);
Because "\n"
is an array of chars. Specifically a char[2]
array, as it is the same as {'\n',0}
. And you cannot assign a char[2]
to a char
.
Even without the null termination you would still not be able to assign it because of the type mismatch. No char[N]
(for a fixed N
) can be assigned to a char
.