C operators

An operator is a symbol that causes specific mathematical or logical manipulations to be performed. The operators available in C include

  • Arithmetic
  • Assignment
  • Relational
  • Increment and decrement
  • Bit
  • Logical

Arithmetic operators

Integers, floating point numbers and double precision numbers can be added, subtracted, divided or multiplied. The operators used for these arithmetic operations are called arithmetic operators. The arithmetic operators in C include addition (+), subtraction (-). multiplication (*), division (/), remainder (%), unary plus (+) and unary minus (-). A simple arithmetic expression consists of an arithmetic operator connecting two arithmetic operands. In an arithmetic expression integer, character or floating-point data types can participate as operands. The following lines represent valid arithmetic expressions

8 + 1
17.89 + 9.8
12 – 0.455

When evaluating arithmetic expressions, the data type of the result is determined by the following rules

  • If all operands are integers, the result is an integer.
  • If any operand is a floating point or double precision value, the result is a double precision number.

Assignment operators

The assignment expression is of the form

Variable = expression;

An assignment expression when followed by a semicolon becomes, an arithmetic expression. The "equal to" symbol (=) is called the assignment operator. It is an operator that assigns the value of the expression on its right side to the variable on its left side.

The two statements

X = Y; and Y = X;

are different and produce different results. A statement such as a =a + 20 can be otherwise written as a+ = 20.

Relational operators 

The relational and equality operators are used to test or compare the value between two operands. The relational or equality operators produce an integer result to express the condition of the comparison. If the condition is false, then the integer result is 0. If the condition is true, then the integer result is a non-zero. C offers the following relational operators

 <         less than
<=       less than or equal to
 >         greater than
>=      greater than  or equal to
!=        not eual to
 ==       equality
=        assignment

Note

In C, equal sign is the assignment operator, whereas the double equal sign is used to test for equality.

Increment and decrement operators

The increment and decrement operators are "add one" and "subtract one". Increment and decrement operators can increment and decrement the value either before of after the value the variable. If the operator appears in front of the variable, it is called a prefix operator. The value  used is the value before it is updated.

++    increment the variable

- -     decrement the variable

Bit operators

C provides six operators for bit manipulation. C operates with complete data entities that are stored as one or more bytes such as character, integer and double precision constants and viables. In addition, C provides for the manipulation of individual bits of character and integer constants and variables.

The operators that are used to perform bit manipulations are called bit operators.

Operator Description
&         Bitwise AND
 |         Bitwise OR
>>       Right shift
<<       Left shift
~        Complement


All operators except ~ operator are binary operators, requiring two operands. In using the bit operators, each operand is treated as a binary number consisting of a series of individual Is and 0s. The respective bits in each operand are then compared on a bit by bit basis and result is determined based on the selected operation.

Logical operators

Logical operators are used to combine two or more relations. The logical operators are called Boolean operators because the tests between values are reduced to either true or false. with zero being false and one being true.

Operator             Description

 !                          NOT

&&                       AND       

 ||                         OR