How can I print a quotation mark in C?

后端 未结 9 1425
臣服心动
臣服心动 2020-11-29 04:38

In an interview I was asked

Print a quotation mark using the printf() function

I was overwhelmed. Even in their off

相关标签:
9条回答
  • 2020-11-29 05:22

    You have to escape the quotationmark:

    printf("\"");
    
    0 讨论(0)
  • 2020-11-29 05:29

    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
    
    0 讨论(0)
  • 2020-11-29 05:31

    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.

    0 讨论(0)
提交回复
热议问题