c转义字符的使用程序举例
时间: 2024-05-16 10:14:34 浏览: 40
C语言转义字符实例详解
下面是一个简单的C程序,演示如何使用转义字符:
```c
#include <stdio.h>
int main() {
printf("Hello\tworld!\n");
printf("This is a backslash: \\ \n");
printf("This is a double quote: \" \n");
printf("This is a single quote: \' \n");
printf("This is a new line: \n ");
printf("This is a carriage return: \r ");
printf("This is a form feed: \f ");
printf("This is a vertical tab: \v ");
printf("This is a backspace: \b ");
return 0;
}
```
输出:
```
Hello world!
This is a backslash: \
This is a double quote: "
This is a single quote: '
This is a new line:
This is a carriage return:
This is a form feed:
This is a vertical tab:
This is a backspace:
```
在这个程序中,我们使用了几个常见的转义字符:`\t` 表示水平制表符,`\n` 表示换行符,`\r` 表示回车符,`\f` 表示换页符,`\v` 表示垂直制表符,`\b` 表示退格符,`\\` 表示反斜杠,`\"` 表示双引号,`\'` 表示单引号。
阅读全文