This article needs additional citations for verification. (January 2019) |
In computer programming, an operator is a programming language construct that provides functionality that may not be possible to define as a user-defined function (i.e. sizeof in C) or has syntax different than a function (i.e. infix addition as in a+b
). Some languages allow a language-defined operator to be overridden with user-defined behavior and some allow for user-defined operator symbols.
Some operators are represented with symbols – characters typically not allowed for a function identifier. For example, a function that tests for greater-than could be named gt
, but many languages provide an infix symbolic operator so that code looks more familiar. For example, this:
if gt(x, y) then return
Can be:
if x > y then return
Operators may also differ semantically from functions. For example, short-circuit Boolean operations evaluate later arguments only if earlier ones are not false.