I think alot of my problem is not understanding what a function is
asking for when it's asking for a pointer. If it's asking for a pointer is
it wanting what the pointer is pointing too. memset for example.
If the function asks for a pointer value, the corresponding argument
must be a pointer value. If the function wants to access the value
pointed to, it is the function's responsibility to dereference the
pointer value. This is what happens in the vast majority of cases,
including your current favorite memset.
On the other hand, there are functions like free and realloc which ask
for a pointer value and may never dereference it.
For standard library functions, you shouldn't care. The function
description tells you what the parameters are used for and your only
concern should be to insure the argument you pass is suitable for that
use.
void *memset (void *s, int c, size_t n);
that first parameter. Is it want a pointer to something or to be passed what
the pointer is pointing to. For example.
Reason it out. Does the compiler know what a pointer to void points
to? Does memset? Do either care? Have you seen any documentation
anywhere that implies the compiler can or does change a pointer type
argument from an address to the data at that address?
int i;
p = &i;
You should be able to explain why this invokes undefined behavior
without the two statements I added.
It should not be a surprise that you can achieve the same effect with
memset(&i, 0, sizeof i);
eliminating both the need for p and dependency in the code on the type
of p or i.
or memset(&p,0,sizeof(int));
memset(&p, 0, sizeof(int*));
You should be able to explain why I made the change and why your code
could potentially invoke undefined behavior depending on certain
system characteristics.
Is such a thing as a function that wants this?
What you coded - no. What I coded is legal but
p = NULL;
accomplishes the same thing much more simply. On the other hand, if p
were a pointer to structure, then
memset(p, 0, sizeof *p);
could be potentially useful but note the lack of an ampersand.
function (int &a, short &b);
If something is defined like that would you just pass the pointer?
You would pass two pointer values, either by specify the names of
pointer objects or by using the & operand on suitable objects. What
other option do you think would work?