Sei sulla pagina 1di 6

Operators In C | Programmerdouts

programmerdouts.blogspot.com/2019/06/operators-in-c.html

OPERATORS
It is a symbol which takes one or more operants(values, variable, etc)
and give some output.
Symbol are knowns as operator

Arithmetic Operators
This operators we are learning since from are childhood days.
This operators need two operants(variable, expression, values) and gives an output.
This operator are known as binary operator.
as binary means two ,so this operator takes two operants.

Operators Name

+ Addition

- Subtraction

* Multiplication

/ Division

% Modulo(Gives an Remainder)

Arithmetic Operators.

Lets understand by an Simple Program

1/6
#include<stdio.h>

main(){
int a ,b,result_add,result_sub,result_mult,result_modulo; // declaring variable
float result_div; // declering the variables

a=10; // initializing the variables


b=15; // initialization of variable

result_add = a+b; //addition operator

result_sub = a - b; // subractopn operator

result_mult = a*b; // multiplication operator

result_div = b/a; // Division operator

result_modulo = b%a; // modulo operator (Gives the Remainder)

printf("Addition of two variable is %d\n",result_add);

printf("Subraction of two variable is %d\n",result_sub);

printf("Product of two variable is %d\n",result_mult);

printf("Division of two variable is %f\n",result_div);

printf("Remainder of two variable is %d\n",result_modulo);


}

Ouput:
Addition of two variable is 25
Subraction of two variable is -5
Product of two variable is 150
Quotient is 1.0000
Remainder is 5

Relational Operators

Operators Name

< Less Than


2/6
> Greater than

<= Less Than Equal to

>= Greater than Equal to

== Equal to

!= Not Equal to

Relational Operators.

Note:This operator are used in Control Structure(Loops,IF-else Statements,etc)


So,Examples of this, we will see in further modules.

Logical Operators
Logical operator are used to check two or more different condition and take
decision According to their values.
This Operators comes in Binary Operator as well in Unary Operator(Need a single
variable or expresions)

Operators Name

&& Logical AND

|| Logical OR

! NOT

Logical Operators.

Note:dont worry if you dont understand it now


Once we will start doing programs you will get an great understanding of it.

CONDITIONS
&&
This operator is a Binary Operator Which Works on Two Operants.
they evaluate According to their conditions
Below Table is truth table of AND Operator

3/6
Operant1 Operant2 Result

True True True

True False False

False True False

False False False

Result is TRUE only if both the Operants


are True.

||
OR Operator is also an Binary Operator Which Works,
On Two Operants
Below is TRUTH Table of OR operator

Operant1 Operant2 Result

True True True

True False True

False True True

False False False

Result is True Even If One of the


operants is True.

!
It is the Unary Operator ,which means it
It works on Single Operant
It Gives the Complementary of the Operator.
Below is Truth Table for NOT Operator.

Operant1 Result

True False

False True

It gives the complement 4/6


It gives the complement
of operants.

Unary Operators

Unary Operator Works on Single Operant.

Operators Name

+ Unary Plus

- Unary Minus

++ Increment

-- Decrement

~ Bitwise Complement

* Indirection

< Address of

! Logical NOT

Unary Operators.

indirection,Address operators are used in Pointers chapter,this we will see in further


modules.
Increment and Decrement behaves very badly.

Operators Name Description

++m Pre this operator adds 1 to a variable and then assign it to a


increment variable on left

--m Pre this operator subtracts 1 from a variable and then assign it to
Decrement a varaible on left

m++ Post this Operator assigns variable to the result and then adds 1
Increment to a variable

5/6
m-- Post this Operator assigns variable to the result and then
Decrement subtracts 1 to a variable

Increment and Decrement.

Note:Mostly increment and decrement comes in Trace output like question,


because they are very messy.

Lets see One Trace the Output Question?


#include<stdio.h>

main(){
int a ,b; // declering the variables
a=10; // initializing the variables
b=15; // initialization of variable

b += ++a;

++b;

a++;

a += b++;

printf("a= %d\tb=%d",a,b);
}

Output
a=39 b=28
Note:we will see more example on "Simple Program" module

6/6

Potrebbero piacerti anche