Re: 0 vs '\0'
- From: "Mabden" <mabden@xxxxxxxxxxxxxx>
- Date: Mon, 12 Sep 2005 11:52:04 GMT
"Richard Tobin" <richard@xxxxxxxxxxxxxxx> wrote in message
news:dg3li2$ssb$1@xxxxxxxxxxxxxxxxxxxxxxxxxx
> In article <fxcVe.51023$4g5.3380805@xxxxxxxxxxxx>,
> DevarajA <no@xxxxxxxx> wrote:
>
> >Are 0 and '\0' the same to terminate a string?
>
> Yes, and they are the same for other purposes too. They both
> represent the integer zero.
>
> The only reason to prefer '\0' is if you think it will make it clearer
> to someone reading the code that it is being used as a character.
>
Well, there is also the issue of whether 0 or \0 is used inside the
string.
char str1[]="Ends with zero...0";
char str2[]="Ends here...\0";
String str1 is 19 chars and the last two chars are an ASCII zero (0x30,
IIRC) and a "char zero" (0x00). strlen() would report 18.
String str2 is 14 chars with 2 "char zeros" at the end. strlen() would
report 12.
--
Mabden
.
- Follow-Ups:
- Re: 0 vs '\0'
- From: DevarajA
- Re: 0 vs '\0'
- References:
- 0 vs '\0'
- From: DevarajA
- Re: 0 vs '\0'
- From: Richard Tobin
- 0 vs '\0'
- Prev by Date: Re: dynamically allocating a 2d array
- Next by Date: Re: Introducing Codase - the first powerful syntax-aware source code search engine
- Previous by thread: Re: 0 vs '\0'
- Next by thread: Re: 0 vs '\0'
- Index(es):
Relevant Pages
|