printf format parameter contain undefined escape c

2019-07-11 04:41发布

问题:

#include <stdio.h>

int main()
{
   printf("Hello\c!\n");
   return 0;
}

Output : Helloc!

So , when \[some_undifined_symbol] appeared in printf 's format string, it just ignore the \ ?

回答1:

\c is not an escape sequence that is already defined, but it's better to avoid using it because it's reserved:

C99 §6.11.4 Character escape sequences

Lowercase letters as escape sequences are reserved for future standardization. Other characters may be used in extensions.



回答2:

You have the following escape sequences defined for c:

  • \' single quote
  • \" double quote
  • \\ backslash
  • \0 null character
  • \a audible bell
  • \b backspace
  • \f form feed - new page
  • \n line feed - new line
  • \r carriage return
  • \t horizontal tab
  • \v vertical tab
  • \nnn arbitrary octal value
  • \xnn arbitrary hexadecimal value