| Subject: | Re: K&R2 , exercise 7.6 |
|---|---|
| From: | Barry Schwarz |
| Date: | Tue, 29 Apr 2008 18:34:16 -0700 |
| Newsgroups: | comp.lang.c |
On Tue, 29 Apr 2008 15:47:30 +0500, arnuld <NoSpam@xxxxxxxxxx> wrote:
>> On Mon, 28 Apr 2008 13:31:18 +0100, Ben Bacarisse wrote:
>
>
>> *buf = 0;
>> char *buf = NULL;
>> char *buf = "";
>>
>> are all different enough to be unlikely alternatives to each other.
>
>*buff = 0;
>
>puts a zero at the place pointed by pointer.
>
>char *buffer = NULL;
>char *buffer = 0;
>
>
>different in what context ? Both are same as of value they contain:
>
>
>
>#include <stdio.h>
>
>
>int main(void) {
>
> char *buffer = 0;
> char *buffer2 = NULL;
>
> printf("%s\n%s\n", buffer, buffer2);
Obviously you wanted to do something else rather than invoke undefined
behavior here. Did you mean to use %p instead of %s? If so, it would
be a good to acquire the habit of casting the pointers to void* (even
though a char* would work without the cast).
>
> return 0;
>}
>
>============ OUTPUT ===============
>/home/arnuld/programs/C $ gcc -ansi -pedantic -Wall -Wextra test.c
>/home/arnuld/programs/C $ ./a.out
>(null)
>(null)
>/home/arnuld/programs/C $
>
>
>
>
>> Arnuld's choice to prefer *buf = '\0'; to my *buf = 0; is fine and
>> needs no correction.
>
> :)
Remove del for email
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: bitshifting, Barry Schwarz |
|---|---|
| Next by Date: | Re: string splitting plzzzzzz help me..., Barry Schwarz |
| Previous by Thread: | Re: K&R2 , exercise 7.6, Ben Bacarisse |
| Next by Thread: | Re: K&R2 , exercise 7.6, arnuld |
| Indexes: | [Date] [Thread] [Top] [All Lists] |