Re: 0 vs '\0'



"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


.



Relevant Pages

  • Re: 0 vs
    ... >Are 0 and '\0' the same to terminate a string? ... and they are the same for other purposes too. ... represent the integer zero. ...
    (comp.lang.c)
  • Re: 0 vs
    ... and they are the same for other purposes too. ... > represent the integer zero. ... And it works as a null pointer constant! ... Prev by Date: ...
    (comp.lang.c)
  • Re: 0 vs
    ... and they are the same for other purposes too. ... >> represent the integer zero. ... Alas, yes. ... Prev by Date: ...
    (comp.lang.c)
  • Re: 0 vs
    ... and they are the same for other purposes too. ... >>> represent the integer zero. ... Does this mean we can go around on the NULL vs Zero Merry-Go-Round, ... Prev by Date: ...
    (comp.lang.c)
  • I need medical abbreviation list and medical drug list
    ... So if anyone could suggest anything which is available online for ... informationd quick look purposes. ... Prev by Date: ...
    (sci.med.transcription)