in Programming in C
336 views
1 vote
1 vote
#include <stdio.h>
int main()
{
char a = '\'';
printf("%c", a);
return 0;
}
in Programming in C
336 views

1 Answer

1 vote
1 vote
Best answer
It prints one single quote '

That backslash \ inside the two single quotes is an escape character. It lets us put ' (single quote) as a character inside the variable a. If this was not present, how would you create a character variable containing ' (single quote) as its value? If you write char a=' ' ' , then the compiler will think you have used the first two single quotes as a way to mark the beginning and ending of the character and the last ' is simply an error. To avoid that, we use special sequences starting with \ which are called escape sequences. There are many escape sequences which have special meanings. Similarly to put a double quote " inside a string variable, we use the expression                  " \" "       so that the compiler does not mistake the second double quote as end of the string.

ex: ' \' '   :  A single quote      \n :  Newline     \b : backspace      etc etc
selected by

Related questions