Home  >  Article  >  Backend Development  >  What is the newline symbol in C language?

What is the newline symbol in C language?

青灯夜游
青灯夜游Original
2023-01-04 14:59:3521096browse

在c语言中,换行符是“\n”,其作用是另起一行,将当前位置移到下一行的开头;“\n”通常在输出中用作格式控制中,例如“printf("文本\n 文本\n");”。“\n”是一个转义字符,因为换行符不是一个可打印的字符,所以通过转义字符来表示。转义字符具有特定的含义,不同于字符原有的意义,故称“转义”字符。

What is the newline symbol in C language?

本教程操作环境:windows7系统、c99版本、Dell G3电脑。

C语言中换行符是'\n',作用是另起一行,将当前位置移到下一行的开头。

\n通常在输出中用作格式控制;

'\n'是一个转义字符,其意义是“回车换行”;因为换行符不是一个可打印的字符,所以通过转义字符来表示。

转义字符以反斜线"\"开头,后跟一个或几个字符。转义字符具有特定的含义,不同于字符原有的意义,故称“转义”字符。

一般放到printf()这类函数中使用,比如:

printf("this is a test\n Please check it\n");

输出:

What is the newline symbol in C language?

常用转义字符

What is the newline symbol in C language?

扩展知识

所有的ASCII码都可以用“\”加数字(一般是8进制数字)来表示。而C中定义了一些字母前加"\"来表示常见的那些不能显示的ASCII字符,如\0,\t,\n等,就称为转义字符,因为后面的字符,都不是它本来的ASCII字符意思了。

转义字符串(Escape String),即字符实体(Character Entity)分成三部分:第一部分是一个&符号,英文叫ampersand;第二部分是实体(Entity)名字或者是#加上实体(Entity)编号;第三部分是一个分号。

比如,要显示小于号(

用实体(Entity)名字的好处是比较好理解,一看lt,大概就猜出是less than的意思,但是其劣势在于并不是所有的浏览器都支持最新的Entity名字。而实体(Entity)编号,各种浏览器都能处理。

【相关推荐:C语言视频教程编程教学

The above is the detailed content of What is the newline symbol in C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn