Skip to main content

C++ Operator And Expression

Programming is nothing but one kinds of problem solver, which can solve different type of problem by using legal logic .for converting logic into program we use some operator.
1.      Arithmetic operators
2.
      Relational operators
3.
      Logical operators
4.
      Increment and decrement operators
5.
      Assignment operator
 
Arithmetic operators


Symbol
Name
Description
Example
+
Add
Adds two operands
A + B
-
Subtracts
Subtracts second operand from the first
A-B
*
Multiplies
Multiplies both operands
A*B
/
Divides
Divides numerator by de-numerator
A/B
%
Modulus
Modulus Operator and remainder of after an integer division
A%B

Relational operators

Symbol
Name
Description
Example
==
Equal
Checks if the values of two operands are equal or not, if yes then condition becomes true.
A==B
!=
Not Equal
Checks if the values of two operands are equal or not, if values are not equal then condition becomes true.
A!=B

Greater than
Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.
A>B
Less than
Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.
A<B
>=
Greater than or equal
Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.
A>=B
<=
Less than or equal
Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.
A<=B

Logical operators

Symbol
Name
Description
Example
&&
And
Called Logical AND operator. If both the operands are non-zero, then condition becomes true.
A&&B
||
Or
Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true.
A||B
!
Nor
Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true, then Logical NOT operator will make false.
!(A&&B)

Increment and decrements operators

Symbol
Name
Description
Example
++
Increment operator
Increases integer value by one
A++
--
Decrements operator
Decreases integer value by one
A--

Assignment operator

Symbol
Name
Description
Example
=
Assignment
Simple assignment operator, Assigns values from right side operands to left side operand
C = A + B
+=
Assignment
Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand
C += A
C = C + A
-=
Subtraction Assignment
Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand
C -= A
C = C - A
*=
Multiplication Assignment
Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand
C *= A
C = C * A
/=
Division Assignment
Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand
C /= A
C = C / A
%=
Modulus Assignment
Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand
C %= A
C = C % A
<<=
Left shift assignment
Left shift AND assignment operator
C <<= 2
C = C << 2
>>=
Right shift assignment
Right shift AND assignment operator
C >>= 2
C = C >> 2
&=
 Bit-wise exclusive And assignmen
Bit-wise AND assignment operator
C &= 2
C = C & 2
^=
Bit-wise exclusive OR Assignment
Bit-wise exclusive OR and assignment operator
C ^= 2
C = C ^ 2
|=
Bit-wise inclusive OR Assignment
Bit-wise inclusive OR and assignment operator
C |= 2
C = C | 2

 


Comments

Popular posts from this blog

Input & Output In C++ (Basic)

Cout<<”Print sentence”;     This statement is use to print out any kinds of sentence or string type values. Cout<<345;     This statement is use to print out any kinds of numeric numbers, without change. Cout<<variable;        This statement is use to print the value of variable. The value of the which variable we want to print, It is need to write that variable on variable place.

Switch, Case, Default Statements In C++

Switch case is uses as alternative of if….else. When we need to use long term of if…else then we use switch case for reducing program execution time. syntax: Switch(variable){ Case value 1: Statement; Break; Case value 2: Statement; Break;

do...while loop in C++

The do while loop is very similar to while loop . In the while loop first check final condition then execute the statement. But in the do while loop first execute the statement then check the final condition. Syntax: Initialization; Do{ increment/decrement;   } while(Final condition)