Search code examples
cpointersb-lang

Why does C use the asterisk to reference the value of a pointer?


I find that I refer to the value at the memory location pointed to by a pointer far more often then I want to refer to the actual value of the pointer. As a result I wonder why C does not use the asterisk in the to refer to the actual value of the pointer since it is more typing.

I have already read a post on another website about how B did it this way. This does not answer my question; it just changes it to why did B do it this way.


Solution

  • I doubt anyone can tell you why it was designed the way it was. But a pointer is a variable that holds an address. Therefore, it's value is the address. I would find it strange and unexpected if it required special syntax to get the value of any variable.

    Note that C++ lets you use references to access the value pointed to without special syntax. But you are dereferencing the pointer, so for me it makes perfect sense to require a different syntax.