Wednesday, February 13, 2013

Operators in C and C++ - C++ Operators - Operators C++ - Implementation of C++ operators

C AND C++ Operators:

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. This is a list of operators in the C and C++ programming languages. All the operators listed exist in C++; the fourth column "Included in C", dictates whether an operator is also present in C. Note that C does not support operator overloading.
                                                             C++ defines keywords to act as aliases for a number of operators. and (&&), bitand (&), and_eq (&=), or (||), bitor (|), or_eq (|=), xor (^), xor_eq (^=), not (!), not_eq (!=), compl (~). These can be used exactly the same way as the symbols they replace as they are not the same operator under a different name, but rather simple text aliases for the name (character string) of respective operator.

Types of Operators
                               1. Arithmetic Operators
                                2. Relational Operators
                                3.Logical Operators
                                4.Bitwise Operators
                                5.Assignment Operators
                               

1.Arithmatic Operators:
                                     Operations of addition, subtraction, multiplication and division literally correspond with their respective mathematical operators. The only one that you might not be so used to see is modulo; whose operator is the percentage sign (%).

OperatorDescriptionExample
+Adds two operandsA + B will give 30
-Subtracts second operand from the firstA - B will give -10
*Multiply both operandsA * B will give 200
/Divide numerator by de-numeratorB / A will give 2
%Modulus Operator and remainder of after an integer divisionB % A will give 0
++Increment operatorA++ will give 11
--Decrement operatoA-- will give 9

2.Relational Operators:
In order to evaluate a comparison between two expressions we can use the relational and equality operators. The result of a relational operation is a Boolean value that can only be true or false.Acording to its Boolean result. 
OperatorDescriptionExample
==Equal(A == B) is not true.
!=Not Equal(A != B) is true.
>Grater Than(A > B) is not true.
<Less Than(A < B) is true.
>=Grater Than(A >= B) is not true.
<=Less Than(A <= B) is true.

3.Logical Operators:
                                  The Operator ! is the C++ operator to perform the Boolean operation NOT, it has only one operand, located at its right, and the only thing that it does is to inverse the value of it, producing false if its operand is true and true if its operand is false.

    Operators                                             Meaning
       &&                                                       AND
       ||                                                         OR
         !                                                         NOT

4.Bitwise Operator:
                                  Bitwise operators modify variables considering the bit patterns that represent the values they store.
operator
asm equivalent
description
&
AND
Bitwise AND
|
OR
Bitwise Inclusive OR
^
XOR
Bitwise Exclusive OR
~
NOT
Unary complement (bit inversion)
<< 
SHL
Shift Left
>> 
SHR
Shift Right

5.Arithmatic Operators:

                                          Operations of addition, subtraction, multiplication and division literally correspond with their respective mathematical operators.
+
addition
-
subtraction
*
multiplication
/
division
modulo.

A simple program in operator:


#include<conio.h>
#include<stdio.h>

void main()
{

int a b;
clrscr();
printf("Enter the value of a=");
scanf("%d",&a);

printf("Enter the value of b=");
scanf("%d",&b);
if(a>b)
printf("a is grater");
else
printf("b is grater");
getch();
}

0 comments:

Post a Comment