C语言 \0 代表什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14461695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 05:06:57  来源:igfitidea点击:

What does \0 stand for?

objective-cc

提问by Saurabh Jadhav

Possible Duplicate:
What does the \0 symbol mean in a C string?

可能的重复:
C 字符串中的 \0 符号是什么意思?

I am new at iPhone Development. I want to know, what does '\0'means in C, and what is the equivalent for that in objective c.

我是 iPhone 开发的新手。我想知道,'\0'C中意味着什么,在目标 c 中的等价物是什么

回答by sr01853

The null character '\0'(also null terminator), abbreviated NUL, is a control character with the value zero. Its the same in Cand objective C

空字符'\0'(也null terminator称为 ),缩写为NUL,是一个值为 的控制字符zero。它在C目标 C 中相同

The character has much more significance in C and it serves as a reserved character used to signify the end of a string,often called a null-terminated string

该字符在 C 中具有更重要的意义,它用作用于表示结尾的保留字符string,通常称为以空字符结尾的字符串

The length of a C string(an array containing the characters and terminated with a '\0'character) is found by searching for the (first) NUL byte.

一个的长度C字符串(包含字符,并用封端的阵列'\0'字符)是通过搜索所发现的(第一)NUL字节

回答by Kerrek SB

In C, \0denotes a character with value zero. The following are identical:

在 C 中,\0表示值为 0 的字符。以下是相同的:

char a = 0;
char b = '
char arr[] = "abc
char str1[] = "Hello";
char str2[] = {'H', 'e', 'l', 'l', 'o', '##代码##'};
def##代码##ghi##代码##";
';

The utility of this escape sequence is greater inside string literals, which are arrays of characters:

这个转义序列在字符串文字中的效用更大,它们是字符数组:

##代码##

(Note that this array has twozero characters at the end, since string literals include a hidden, implicit terminal zero.)

(请注意,该数组的末尾有两个零字符,因为字符串文字包含一个隐藏的、隐式的终结符零。)

回答by dasblinkenlight

The '\0'inside character literals and string literals stands for the character with the code zero. The meaning in C and in Objective C is identical.

'\0'内部字符文字和字符串表示的代码零的字符。在 C 和 Objective C 中的含义是相同的。

To illustrate, you can use \0in an array initializer to construct an array equivalent to a null-terminated string:

为了说明这一点,您可以\0在数组初始值设定项中使用来构造一个等效于以空字符结尾的字符串的数组:

##代码##

In general, you can use \oooto represent an ASCII character in octalnotation, where os stand for up to three octal digits.

通常,您可以使用八进制表示法\ooo来表示 ASCII 字符,其中s 最多代表三个八进制数字。o

回答by Steve Jessop

To the C language, '\0'means exactly the same thing as the integer constant 0(same value zero, same type int).

对 C 语言来说,'\0'意味着与整型常量完全相同的东西0(相同的值零,相同的类型int)。

To someone reading the code, writing '\0'suggests that you're planning to use this particular zero as a character.

对于阅读代码的人来说,写作'\0'表明您计划使用这个特定的零作为字符。

回答by Ivaylo Strandjev

\0is zero character. In Cit is mostly used to indicate the termination of a character string. Of course it is a regular character and may be used as such but this is rarely the case.

\0是零字符。在C它主要用于指示字符串的终止。当然,它是一个常规字符,可以这样使用,但这种情况很少见。

The simpler versions of the built-in string manipulation functions in Crequire that your string is null-terminated(or ends with \0).

内置字符串操作函数的更简单版本C要求您的字符串以空字符结尾(或以 结尾\0)。

回答by Hyman

In C \0is a character literal constant store into an intdata type that represent the character with value of 0.

在 C\0中,字符常量存储到int表示值为 0 的字符的数据类型中。

Since Objective-C is a strict superset of C this constant is retained.

由于Objective-C 是C 的严格超集,因此保留了这个常量。

回答by ProfessionalAmateur

It means '\0' is a NULLcharacter in C, don't know about Objective-Cbut its probably the same.

这意味着 '\0' 是NULLC 中的一个字符,不知道Objective-C但它可能是一样的。