Previous | Home | Next |

operator is a special type of function that takes one or more argument and produce the new value. operator are used to perform various operation and variables.

*Arithmetic Operator:*The basic Arithmetic operation can be included in VC++. And operators having the same meaning as the other languages.*Relational Operator:*The basic Relational operator established the relationship between operands. various relation operator are includes.*Logical Operator:*Logical operator are used to define the relation and combine logically or expressions. a particular condition is true or false, they can only test one condition at a time.*Assignment Operator:*The assignment operator is used to copy the values from one object to another already existing object.*Increment and Decrement Operators:*Incrementing (adding 1 to) and decrementing (subtracting 1 from) a variable. increment and decrement operator works only with integer variables. a disadvantage of increment/decrement operators is that the variable can only incremented or decremented by the value one.*Conditional Operator:*conditional operator(?:) is ternary operator (including 3 operand) and is used certain situation. replacing if else condition phrases. conditional operator defined as a (Condition_phrase ? phrase1:phrase2;). if condition phrase is true so phrase1 is executed and whole phrase is assigned with the value of this phrase1. and if the condition phrase is false then phrase2 is executed and whole phrase value is assigned with phrase2 value .
*Bitwise operator:*A bitwise operator is an operator used to perform bitwise operation on it patterns or binary numerals that involve the manipulation of individual bits.Bitwise data manipulation is working with data at the bit level, instead of working with bytesor larger units of data, is more common. Bitwise operators are similar in most languages that support them.

Operator | Function |

+ | Addition |

- | subtraction |

* | Multiplication |

/ | Division |

% | Remender |

### Example:

#include <iostream> using namespace std; int main() { int firstnum; int secondnum; int Sum, Subtraction, Multiplication, Division; cout << "Enter first integer: "; cin >> firstnum; cout << "Enter second integer: "; cin >> secondnum; Sum = firstnum + secondnum; Subtraction = firstnum - secondnum; Multiplication = firstnum * secondnum; Division = firstnum / secondnum; cout << "The Sum is: " << Sum << endl; cout << "The Subtraction is: " << Subtraction << endl; cout << "The Multiplication is: " << Multiplication << endl; cout << "The Division is: " << Division << endl; return 0; }

Operator | Discription |

< | Less than |

<= | Less then or equal to |

> | Greater than |

>= | Greater than or equal to |

= | Equal to |

== | Equal's Equal to |

!= | Not Equals to |

### Example:

#include <iostream> using namespace std; int main() { int a; int b; cout << "Enter two integers to compare: "; cin >> a >> b; if ( a < b ) cout << a << " < " << b << endl; if ( a <= b ) cout << a << " <= " << b << endl; if ( a > b ) cout << a << " > " << b << endl; if ( a >= b ) cout << a << " >= " << b << endl; if ( a = b ) cout << a << " = " << b << endl; if ( a == b ) cout << a << " == " << b << endl; if ( a != b ) cout << a << " != " << b << endl; return 0; }

Symbole | Operator | Discription | Example |

&& | AND Operator | Its return the true when both operand are true. | A>b && A>c (1 is true). A>b && A<c ( 0 is false). A<b && A<c (0 is false). |

! | NOT Operator | Its return the false when both operands are true. | A>b && A>c (0 is false). A>b && A>c ( 0 is false). A>b&A<c (1 is true). |

|| | OR Operator | Its return the true when both operands are equals. | A>b || A>c (1 is true). A>b || A<c (0 is false). A<b || A<c (1 is true). |

### Example:

#include <iostream> using namespace std; void main() { int percentage; cout << "Enter the percentage::"; cin >> percentage; if ((percentage!=35)&&(percentage>45 && percentage<65) ) { cout << "passed is in the Middle of the percentage" ; } else if (percentage<35 || percentage>100) { cout << "Enter a valid percentage"; } else { cout << "passed"; } }

### Example:

int main() { int a, b; A = 10; B = A + 1; A = B - 3; return 0; }

Operator | Symbol | Form | Operation |

Prefix increment | ++ | ++A | Increment A, then evaluate A |

Prefix decrement | -- | --A | Decrement A, then evaluate A |

Postfix increment | ++ | A++ | Evaluate A, then increment A |

Postfix Decrement | -- | A-- | Evaluate A, then decrement A |

#include <iostream> using namespace std; int main() { int X = 50; int Y ; Y= X++; cout << " Value of X++ is :" << X << endl ; cout << " Value of X is :" << X << endl ; Y = ++X; cout << " Value of ++X is :" << Y << endl ; return 0; }

### Example:

#include<iostream> using namespace std; int main() { int weight, height; cin >> weight; cin >> height; if(height == weight) { cout << "Your height is equal to your weight!"; } else if(height < weight) { cout << "Your height is less than your weight!"; } else if(height > weight) { cout << "Your height is greater than your weight!"; } else { cout << "you need to advise physical trainer!"; } return 0; }

Operator | Symbol | Discription |

OR | | | Result is true if any of the operands is true. |

AND | & | Result is true only if both operands are true. |

XOR | ^ | Result is true only if one of its operands is true. It is used mainly to toggle certain bits. |

Bitwise Complement or Inversion or NOT | ~ | Provides the bitwise complement of an operand by inverting its value such that all zeros are turned into ones and all ones are turned to zeros. |

Left shift | << | Shifts first operand a number of bits to the left as specified in the second operand, shifting in zeroes from the right |

Right shift | >> | Shifts first operand a number of bits to the right as specified in the second operand, and discards displaced bits |

Previous | Home | Next |