字符常量:\\ 000 \\ XHH [英] character constant:\000 \xhh

查看:466
本文介绍了字符常量:\\ 000 \\ XHH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以请解释字符常量\\ 000和用法\\ XHH即八进制的字符常量数字和十六进制数字?

Can anyone please explain the usage of the character constant \000 and \xhh ie octal numbers and hexadecimal numbers in a character constant?

推荐答案

在C,字符串由一个字符结束零值(0)。这可能是这样写的:

In C, strings are terminated by a character with the value zero (0). This could be written like this:

char zero = 0;

但是,这并不在里面工作的字符串。有一个在字符串,其中反斜线作为工作的转义序列引入使用一种特殊的语法,并且是其次的各种事情。

but this doesn't work inside strings. There is a special syntax used in string literals, where the backslash works as an escape sequence introduction, and is followed by various things.

一个这样的序列为反斜线零,即仅仅意味着与零值的一个字符。因此,你可以这样写:

One such sequence is "backslash zero", that simply means a character with the value zero. Thus, you can write things like this:

char hard[] = "this\0has embedded\0zero\0characters";

另一个序列使用反斜杠后跟字母'X'和一个或两个十六进制数字,重新present与指示code中的角色。使用这个语法,你可以比如写零字节为'\\ X0'

Another sequence uses a backslash followed by the letter 'x' and one or two hexadecimal digits, to represent the character with the indicated code. Using this syntax, you could write the zero byte as '\x0' for instance.

修改:重读的问题,但也是一个在基地八项这样的常量支持,即八进制。他们用一个反斜杠后跟数字零,就如同字面上的八进制整数常量。 '\\ 00'因而是一个同义词'\\ 0'

EDIT: Re-reading the question, there's also support for such constants in base eight, i.e. octal. They use a backslash followed by the digit zero, just as octal literal integer constants. '\00' is thus a synonym for '\0'.

当你需要构建包含非打印字符,或特殊控制字符的字符串这是有时是有用的。

This is sometimes useful when you need to construct a string containing non-printing characters, or special control characters.

还有一个组一个字符的命名为特殊字符,如的'\\ n'为换行,'\\ T'为TAB,等等。

There's also a set of one-character "named" special characters, such as '\n' for newline, '\t' for TAB, and so on.

这篇关于字符常量:\\ 000 \\ XHH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆