DEV Community

Discussion on: Why use pointers at all.

Collapse
 
pentacular profile image
pentacular

I think it's important to note that passing a pointer by value is not pass by reference.

Passing the pointer by value grants the means to reference the thing pointed at on the other side, but it doesn't have pass-by-reference semantics.

e.g., this code can't change the value of p, so bar will always receive a null pointer value.

{
  int *p = 0;
  foo(p);
  bar(p);
}

If p were passed by reference then the value of p could be changed by the call to foo.