0

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);
John Kugelman
  • 349,597
  • 67
  • 533
  • 578

1 Answers1

0

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.

bitmask
  • 32,434
  • 14
  • 99
  • 159