C Operators :

Operators and Expressions :

  1. Arithmetic
  2. Relational operators
  3. Logical operators
  4. Increment and Decrement operators
  5. Assignment operators
  6. Conditional operator
  7. Bitwise operators

Arithmetic Operators :

OperatorMeaningExampleResult
+addition5+27
-subtraction5-23
*multiplication5x210
/division5/22
%modulus operator to get remainder in integer division5 % 21

Relational Operators :

OperatorMeaningExampleResult
<less than5<2false
>greater than5>2true
<=less than or equal to5<=2false
>=greater than or equal to5>=2true
==equal to5==2false
!=not equal to5!==2true

Logical Operators :

OperatorMeaningExampleResult
&&logical and(5<2)&&(5>3)false
||logical or(5<2)||(5>3)true
!logical not (negation)!(5<2)true

Note : logical not(!) is unary operator which requires only one operand (true to false and vice versa).

Increment and Decrement operators :

Increment operator (++) is used to increase the value of an integer or char variable.
Decrement operator (--) is used to reduce the value of an integer or char variable.

Examples :

m = 15;
m++ or ++m will produce the result m = 16.

m = 15;
m-- or --m will produce the result m = 14.

Note : That m++ and m-- are referring the post-fix increment and decrement operation, and ++m and --m are referring the prefix increment and decrement operation.

Assignment Operators :

OperatorMeaningExampleResult
+=m += 10m = m + 1025
-=m -= 10m = m - 105
*=m *= 10m = m * 10150
/=m /= 10m = m / 101
%=m %= 10m = m % 105

Conditional Operators :

Conditional operator is used to check a condition and select a value depending on the condition. Normally the selected value will be assigned to a variable which ha the following form.

variable = (condition) ? value 1 : value 2;
When this operator is execute by the computer, the value of the condition is evaluated. If it is true then value 1 is assigned to the variable, otherwise value 2 is assigned to the variable. Consider the following example.

big = ( a > b ) ? a : b
In this operation, the computer checks the value of the condition (a>b); If it is true a is assigned to big; otherwise b is big.

Conditional operator, like assignment operators, is also more concise and more efficient.

Bitwise Operators :

OperatorMeaning
<<shifts the bits to left
>>shifts the bits to right
~bitwise inversion (one's complement)
&bitwise logical and
|bitwise logical or
^bitwise exclusive or

Computer Science Engineering

Special Notes

It's a special area where you can find special questions and answers for CSE students or IT professionals. Also, In this section, we try to explain a topic in a very deep way.

CSE Notes