HiveBrain v1.2.0
Get Started
← Back to all entries
patternMajor

Is there any reason why the modulo operator is denoted as %?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
whytheoperatordenotedanyreasontheremodulo

Problem

I would like to know if there is any reason why many programming languages use the notation % for the modulo operator?

It is used in the most "famous" languages:

  • C



  • C++



  • C#



  • Go



  • Java



  • Julia



  • Lua



  • Perl



  • Python

Solution

The earliest known use of % for modulo was in B, which was the progenitor of C, which was the ancestor (or at least godparent) of most languages that do the same, hence the operator's ubiquity.

Why did Thompson and Richie pick %? It had to be a printable ASCII character that wouldn't conflict with B's other features. % was available, and it resembles the / division operator, making it the obvious choice.

p.s. the creator of ASCII invented \ to represent "reverse division", so it wasn't a candidate for modulo.

Context

StackExchange Computer Science Q#133386, answer score: 45

Revisions (0)

No revisions yet.