预测以下程序的输出。
#include <stdio.h>
int main()
{
printf(" \"TEST %% C %% PROGRAM\"");
return 0;
}
答案是“测试%C%程序”
为什么?我明白 %% 意味着它将打印 % ,但是 printf 中的 "\"\"东西怎么样?最佳答案
您需要使用字符串分隔符来定义字符串的开头和结尾,例如
"Taha Paksu was here"
但是如果您需要在字符串中使用引号怎么办?喜欢:
""Taha Paksu" was here" (you can see that the code highlighter is confused too)
那么编译器就会对字符串的开头和结尾感到困惑。
为了防止这种情况发生,存在转义序列。要在引号分隔的字符串中写入引号,您需要先对其进行转义。喜欢
"\"Taha Paksu\" was here"
\
字符用于描述转义序列,例如:
Escape sequence Hex value in ASCII Character represented
\a 07 Alert (Beep, Bell) (added in C89)[1]
\b 08 Backspace
\f 0C Formfeed
\n 0A Newline (Line Feed); see notes below
\r 0D Carriage Return
\t 09 Horizontal Tab
\v 0B Vertical Tab
\\ 5C Backslash
\' 27 Single quotation mark
\" 22 Double quotation mark
\? 3F Question mark (used to avoid trigraphs)
\nnn note 1 any The byte whose numerical value is given by nnn interpreted as an octal number
\xhh… any The byte whose numerical value is given by hh… interpreted as a hexadecimal number
\e note 2 1B escape character (some character sets)
\Uhhhhhhhh note 3 none Unicode code point where h is a hexadecimal digit
\uhhhh note 4 none Unicode code point below 10000 hexadecimal
如果想以字符串形式输出\
;您还需要使用 \\
关于c - 需要有关 c 中 printf() 的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48208739/