In an interview I was asked
Print a quotation mark using the
printf()
function
I was overwhelmed. Even in their off
You have to escape the quotationmark:
printf("\"");
In C programming language, \
is used to print some of the special characters which has sepcial meaning in C. Those special characters are listed below
\\ - Backslash
\' - Single Quotation Mark
\" - Double Quatation Mark
\n - New line
\r - Carriage Return
\t - Horizontal Tab
\b - Backspace
\f - Formfeed
\a - Bell(beep) sound
This one also works:
printf("%c\n", printf("Here, I print some double quotes: "));
But if you plan to use it in an interview, make sure you can explain what it does.
EDIT: Following Eric Postpischil's comment, here's a version that doesn't rely on ASCII:
printf("%c\n", printf("%*s", '"', "Printing quotes: "));
The output isn't as nice, and it still isn't 100% portable (will break on some hypothetical encoding schemes), but it should work on EBCDIC.