The main reason for choosing certain characters has been accessibility of said characters. Today, we have Unicode and we can easily type characters such as
← with our Compose Key¹. That arrow was used as the assignment in APL (
a ← b + c).
IBM had a specialized keyboard that allowed you to type those special APL (math, really) characters:
But various solutions were looked at to provide ways for regular people to type programs without the need for those special characters. For example, the
← APL operator actually became the
:= operator still in use in Pascal and Ada (and invalid use in Go & Perl).
C had a similar issue and also clearly mentioned the fact that someone with just ASCII characters should be able to enter programs. Actually, it was "the old ASCII" without the characters 0x60 to 0x7E (the ```, lowercase
~). So the digraph (Pascal
*) for comments) and the trigraph (C
??! for the
| character) were introduced. Now the trigraph have been deprecated and by default are not supported in C/C++ (finally).
That being said, the reason for the
| in the C language (which is the first programming language using that operator), is most certainly following the choice in Backus-Naur as mentioned by @virolino above. The math operators are the "∨" for OR and "∧" for AND, which we cannot type in ASCII and definitely do not look like the
| character. Note, however, that the original symbols were different:
Naur changed two of Backus's symbols to commonly available characters. The
::= symbol was originally a
| symbol was originally the word "or" (with a bar over it).: 14
In other words:
or became |
It is not clear to me which came first, Naur's change or the C language. My guess is that Naur's change happened first.
¹ The Compose Key has been available on Ubuntu for years. If you did not turn it one when installing Ubuntu, you'll find it in your preferences. Look here for MS-Windows and here for Mac OS.