Differences between single-quotes and double-quotes in C

前端 未结 5 469
梦如初夏
梦如初夏 2021-01-29 16:39

Recentely I have seen that if I use printf with \'foo\' I get a warning.

printf(\'numero\');

warning: character con

5条回答
  •  自闭症患者
    2021-01-29 17:07

    In c the string delimiter is ", the ' is used for character constants.

    The double quotes " will generate a string, a sequence of bytes with a terminating '\0' byte.

    Example:

    const char *string = "Example";
    /* the sequence -> ['E', 'x', 'a', 'm', 'p', 'l', 'e', '\0'] is generated */
    

    The ' will generate an integer, in the case of a single character it's the ascii value that it represents, in case of multiple characters it's implementation defined.

    Example:

    char A = 'A'; /* the ascii value of 'A', 0x41 or 65 decimal */
    

    Multicharacter strings, will also generate an integer, but it's value changes depending on the c implementation/compiler.

提交回复
热议问题