Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does \0 stand for? [duplicate]

Tags:

c

objective-c

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.

like image 283
Saurabh Jadhav Avatar asked Jan 22 '13 15:01

Saurabh Jadhav


People also ask

What is the meaning of '\ 0?

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.

What is the meaning of '\ 0 in C?

'\0' is referred to as NULL character or NULL terminator It is the character equivalent of integer 0(zero) as it refers to nothing In C language it is generally used to mark an end of a string.

What is the meaning of \0 in string?

'\0' is referred to as NULL character or NULL terminator It is the character equivalent of integer 0(zero) as it refers to nothing. In C language it is generally used to mark an end of a string.

Does '\ 0 take up memory?

\0 is just one more character from malloc and free perspective, they don't care what data you put in the memory. So free will still work whether you add \0 in the middle or don't add \0 at all. The extra space allocated will still be there, it won't be returned back to the process as soon as you add \0 to the memory.


2 Answers

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.

like image 104
sr01853 Avatar answered Sep 21 '22 01:09

sr01853


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.)

like image 36
Kerrek SB Avatar answered Sep 21 '22 01:09

Kerrek SB