Skip to main content

Operators

 

The operations are represented by operators and the object of the operation are referred to as operands.

5 types of operators:

1. Arithmetic Operator 

  • Addition : 2 + 4 = 6
  • Subtraction : 2 - 4 = -2
  • Multiplication : 2 * 4 = 8
  • Division : 2 / 4 = 0
  • Modulus (remainder operator, used only with integer values) : 7 % 2 = 1

2. Increment (++) / Decrement (--) Operator

Increment Operator increases its operand value by 1 while decrement operator decreases its operand value by 1. 

They both have two types :

  • Prefix : First it will increase (or decrease) the operand value by one and then participate in the operation.

  • Postfix : First it will participate in the operation and then increase (or decrease) the operand value by 1.

3. Relational Operator

They determine the relation among different operands. But they do not work with strings.

6 types of relational operator are:

  • > greater than
  • < less than
  • >= greater than or equals to
  • <= less than or equals to
  • == equal to
  • != not equal to

If the comparison is true then relational operator returns 1 otherwise 0.

4. Logical Operator

C++ provides 3 logical operators to combine existing expressions :

  • && : logical AND represents multiplication
  • || : logical OR represents addition
  • ! : logical NOT represents compliment or reverse

5. Conditional Operator

C++ offers a conditional operator ( ? : ) that stores a value depending upon a condition.

It is a ternary operator i.e, it requires 3 operands.

Syntax : (expression 1) ? (expression 2) : (expression 3)

If expression 1 evaluates to true then result will be expression 2 otherwise result will be expression 3.

Comments

Popular posts from this blog

Data Representation

 Digital Number System In digital representation, various number systems are used. The most common ones are : Binary : base 2 (0, 1) Octal : base 8 (0, 1, 2, 3, 4, 5, 6, 7) Decimal : base 10 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) Hexadecimal : base 16 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) Number Conversions : From Decimal to any system (base) (Decimal) 10 = (Any) base