Mail Archives: djgpp/1998/05/03/00:35:04
I am still rather new to C programming, but there is something I remembered from a
book on C programming that was describing pointers to variables and when it came to
the scanf() function the only type of variable you didn't use & with was a string
variable because it is a pointer to a character array variable (there are no
strings in C). So as far as I can tell, you should be able to use
memset(strbuf, 0, 13);
just fine, without the & (address of) operator because strbuf is already a
pointer. If you see what I mean.
As for other compilers having problems with that, they may have had problems if
you placed an & in front because it is a pointer and doesn't need an & (string
variables are really just pointers to character arrays).
I hope this helped you. If need be I can look up the chapter and quote you
what I read if I wasn't clear enough.
Happy programming;
Neil "NiteHackr" Roy
Fist1000 wrote:
> If I have an array, for example:
>
> char strbuf[13];
>
> what does &strbuf, yield? I usually do the following to zero such an array:
>
> memset(strbuf, 0, 13);
>
> or
>
> memset(&strbuf[0], 0, 13);
>
> but i've recently noticed the following in someone else's code:
>
> memset(&strbuf, 0, 13);
>
> I thought this was invalid, but it seems to compile. I'm no master of pointers
> or references, but that seems incorrect. I've been porting some code from DJGPP
> to Watcom, and in many cases in the Watcom code, it doesn't like &strbuf and
> will give me a bunch of bogus data. Anyone have any insight into this? Please
> reply by e-mail. Thanks.
>
> Later,
> Aen (fist1000 AT aol DOT com)
- Raw text -