Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
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
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
== Equal to
!= Not Equal to
Relational Operators.
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 OR
! NOT
Logical Operators.
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
||
OR Operator is also an Binary Operator Which Works,
On Two Operants
Below is TRUTH Table of OR operator
!
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
Unary Operators
Operators Name
+ Unary Plus
- Unary Minus
++ Increment
-- Decrement
~ Bitwise Complement
* Indirection
< Address of
! Logical NOT
Unary Operators.
--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
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