Why is `&` used for both binary AND addresses in C?

This question is in answer to What is && & & in C , which made me think of & , used as a binary AND and an address.

Why is the same character used for both very different tasks? If you think about it, @ will turn out to be the best character for an address.

I do not expect this to cause many problems in practice, since the compiler will probably catch the most erroneous use, but it will probably be possible to create code using macros that looks like it is executing AND binary while it actually executes Address of.

+6
source share
2 answers

The reason @ not used for the "address" (as you suggested, it would be a good choice) is that this character was not part of the ISO 646 character set, which was actually used in the early days of C.

Although it is true that C designers could use @ and developed a trigraph sequence for it, I suspect that they felt that it wasn’t worth it. The fact that &&& might appear in people’s code was probably not considered sufficient reason for choosing another operator character.

+7
source

I don’t think there is any big reason why it was used for two different things.

Fortunately, there is no ambiguity in the language, because one use is a unary operator and the other is a binary operator (i.e. it has two operands). The same goes for * (multiplication or dereferencing).

+7
source

All Articles