What does \0 stand for? [duplicate]

2020-08-10 08:08发布

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

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.

标签: objective-c c
7条回答
冷血范
2楼-- · 2020-08-10 08:35

The null character '\0' (also null terminator), abbreviated NUL, is a control character with the value zero. Its the same in C and objective 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

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.

查看更多
放我归山
3楼-- · 2020-08-10 08:36

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

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

查看更多
▲ chillily
4楼-- · 2020-08-10 08:45

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

char a = 0;
char b = '\0';

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

char arr[] = "abc\0def\0ghi\0";

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

查看更多
何必那么认真
5楼-- · 2020-08-10 08:53

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

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

查看更多
冷血范
6楼-- · 2020-08-10 08:55

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

查看更多
趁早两清
7楼-- · 2020-08-10 08:57

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.

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

char str1[] = "Hello";
char str2[] = {'H', 'e', 'l', 'l', 'o', '\0'};

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

查看更多
登录 后发表回答