Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 03 Jun 2011 17:38:29 -0500 Message-ID: <4DE96267.29C3@mindspring.com> Date: Fri, 03 Jun 2011 18:38:31 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: Questions Regarding Null and Casting References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 44 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.219.122 X-Trace: sv3-jW8wWWtoLfFbqBh/TzraDx47iy39J4iyq+KB/fvnyWu1qvB5jN1QI9xDcK4bjC8NjZMnqyXM2RCO7W6!ZaQ36G9Q3k/yLqDeeqqHzDkpmC4NQYDe4TRbT7FjURiILtK8ManjWDur/TLpZ8TE6wJYk/pxdh2i!A64KtHRflnE= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2459 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:5395 BigChuck19 wrote: > To check if malloc() returns NULL or not, > why couldn't one write " if (grades == NULL) ". One could; there's absolutely nothing wrong with it. > Say I create a character array called array. > After initializing all its entries, I then want > to clear the entire array by making > each entry hold the null character. I > could write something like the following to accomplish this: > > for(i = 0; i < MAXTENTRIES; i++) > array[i] = '\0'; > > Does the following loop perform the identical operation? > > for(i = 0; i < MAXENTRIES; i++) > array[i] = (char) NULL; No. > I am confused about the definition of NULL and the use of NULL; It is best to use NULL in a pointer context regardless of how any particular implementation defines NULL. NULL expands to an implementation-defined null pointer constant. An integral constant expression with the value 0, or such an expression cast to type void * , is called a null pointer constant. An integral constant expression shall have integral type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof expressions, and floating constants that are the immediate operands of casts. Cast operators in an integral constant expression shall only convert arithmetic types to integral types, except as part of an operand to the sizeof operator. -- pete