From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29098 invoked by alias); 8 Aug 2008 12:10:52 -0000 Received: (qmail 29087 invoked by uid 22791); 8 Aug 2008 12:10:52 -0000 X-Spam-Check-By: sourceware.org Received: from gamma.dmkhost.com (HELO gamma.dmkhost.com) (67.19.42.2) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 08 Aug 2008 12:09:58 +0000 Received: from [195.24.248.244] (port=49175 helo=[192.168.1.100]) by gamma.dmkhost.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1KRQml-000270-RG; Fri, 08 Aug 2008 14:09:36 +0200 Message-ID: <489C3791.1050801@loskot.net> Date: Fri, 08 Aug 2008 13:00:00 -0000 From: Mateusz Loskot User-Agent: Thunderbird 2.0.0.16 (Macintosh/20080707) MIME-Version: 1.0 To: Rohit Arul Raj CC: gcc-help Subject: Re: odd behavior with Character Arrays References: <489BEDB7.2020905@loskot.net> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-08/txt/msg00071.txt.bz2 Rohit Arul Raj wrote: > On Fri, Aug 8, 2008 at 12:24 PM, Mateusz Loskot wrote: >> Rohit Arul Raj wrote: >>> 2. Can i get more details as to why if the size of the array is not >>> provided the compiler does not insert an string terminator at the end >>> of the array. >> How could that be? >> It is an array but not a string literal, so compiler does not append \0 or >> any other extra elements to it. >> >> Best regards >> -- >> Mateusz Loskot, http://mateusz.loskot.net >> Charter Member of OSGeo, http://osgeo.org >> > > > Hi, > > If i give the size of the array as 15, like "unsigned char n[15] = > {'a', 'b', 'c','d'};" , then it is appending '\0'. Rohit, Yes, this is perfectly correct. > But if the size of the array is not given "unsigned char n[] ", then > it is not appending '\0'. And this is correct behavior and I was referring to the n[] case only. Sorry for lack of precision. > Does that mean, that if the size of the array is specified, it appends > '\0' and if it is not specified then it does not append '\0'? > Can you/anyone clarify this point? I believe Jerzy explained it in details. Best regards, -- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org