K
Keith Thompson
Old Wolf said:Richard said:Yes, but that only sets a single member to all bits zero.
It sets the entire object (*arr) to all-bits-zero. Examples:
struct S { int a[20]; };
S s, *p = &s;
int (*q)[20] = &s.a;
memset(p, 0, sizeof *p); // good
memset(q, 0, sizeof *q); // also good
If you have a pointer, not an array, memset() cannot find out for itself
how many members there are
If you have a pointer to the object, then you can zero it.
Otherwise, you can't. (A pointer to part of the object doesn't count).
A pointer to part of the object does count if you have additional
information. A pointer to the first element of an array can be used
to zero the entire array if you know (by some other means) how many
elements the array has. For example:
memset(ptr, 0, COUNT * sizeof *ptr);
Of course if you meant "doesn't count" literally, you're correct, but
I assumed it was just a figure of speech.