Operator (computer Programming)
Programming languages typically support a set of operators: operations which differ in the calling of syntax and/or the argument passing mode from the language's functions. Common examples that differ by syntax are mathematical arithmetic operations, e.g. ">" for "greater than", with names often outside the language's set of identifiers for functions, and called with a syntax different from the language's syntax for calling functions. Common examples that differ by argument passing mode are boolean operations, e.g. a short-circuiting conjunction that only evaluates later arguments if earlier ones are not false, in a language with strict call-by-value functions.
A language may contain a fixed number of built-in operators (e.g. + - * = in C and C++), or it may allow the creation of programmer-defined operators (e.g. Haskell). Some programming languages restrict operator symbols to special characters like + or := while others allow also names like div
(e.g. Pascal).
Some built-in operators supported by a language have a direct mapping to a small number of instructions commonly found on central processing units, though others (e.g. '+' used to express string concatenation) may have complicated implementations.
The specification of a language will specify the precedence and associativity of the operators it supports. Languages which support programmer-defined operators require the specification of the precedence and associativity of new operator symbols (e.g. Prolog).
Most programming language operators take one or two operands, with a few supporting more operands (e.g., the ?: operator in C). The position of the operator with respect to its operands may be prefix, infix or postfix.
Syntactically operators usually contrast to functions. In most languages, functions may be seen as a special form of prefix operator with fixed precedence level and associativity, often with compulsory parentheses e.g. Func(a)
(or (Func a)
in LISP). Most languages support programmer-defined functions, but cannot really claim to support programmer-defined operators, unless they have more than prefix notation and more than a single precedence level. Semantically operators can be seen as special form of function with different calling notation and a limited number of parameters (usually 1 or 2).
A compiler can implement operators and functions with subroutine calls or with inline code.
Read more about Operator (computer Programming): Operator Overloading, Operand Coercion, Operator Features in Programming Languages