Re: char array not terminated with \0

From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 01/17/05


Date: Mon, 17 Jan 2005 21:23:21 GMT


"Artie Gold" <artiegold@austin.rr.com> wrote in message
news:35182lF4cf691U1@individual.net...
> thesushant@rediffmail.com wrote:
> > hi,
> > statements like char str[12]="012345678901", dont suffix "\0" after the
> > array of characters or strings on its own . or the programmer has to
> > give it explicitly??????????????
> >
> Don't top post. I've snipped the original message, as yours provides
> enough context.
>
> The issue in the definition above is that the array `str' is declared to
> have sufficient room for only 12 chars; the '\0' would be appended *if
> there was room for it*.

For completeness:

Also, a '\0' would be appended if the size were computed
by the compiler, as happens when no size is explicitly specified:

char str[] = "abc"; /* array size is 4 */

-Mike



Relevant Pages

  • Re: Counting criteria
    ... As you are talking about completeness, Max, please remember when replying to ... a message to quote enough of the original message to put your reply into ... context. ...
    (microsoft.public.excel.misc)
  • Re: ANN (retry): C compliler, new download available
    ... The context between them is irrelevant to my statements. ... architecture or is compiled by a "normal" compiler, ... creating portable code for some architecture you can't test on. ...
    (alt.lang.asm)
  • Re: Overloading and method signatures.
    ... some part of my brain has been spoiled by Perl. ... Console.WriteLine("the number is " + theNumber); ... Knowing that the expression is in "string context", the compiler calls ...
    (microsoft.public.dotnet.csharp.general)
  • Re: Overloading and method signatures.
    ... some part of my brain has been spoiled by Perl. ... Console.WriteLine("the number is " + theNumber); ... Knowing that the expression is in "string context", the compiler calls ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Mail etiquette (was: What is this mean by this term)
    ... different people configure and use their email clients in different ... message as soon as it arrives. ... There it is often the case that people do not have the original message ... to get the context from. ...
    (freebsd-questions)