SlideShare a Scribd company logo
Arithmetic operators
1. Unary operators
2. Binary operators
 Assignment operators
 Equalities and Relational operators
 Logical operators
 Conditional operators



In C , we have the following operators.
operation

operator

initialization

Addition

+

a+ b = c

Subtraction

-

a-b=c

Multiplication

*

a*b=c

Division

/

a/b=c

Increment

++

a++

Decrement

__

a--

Modulus

%

a%b=c


There are two types of arithmetic operators in
C:
1. Unary operators:
•

Operators that require only one operand

2. Binary operators:
•

Operators that require two operands.
C operation

operator

Example

Positive

+

a = +3

Negative

-

b = -a

Increment

++

i++

decrement

--

i--

The first assigns the positive value of 3 to a.
The second assigns the negative value of a
i++ is equivalent to i = i + 1.
i-- is equivalent to i = i - 1.

to b.





It is also possible to use ++i and –-i instead
of i++ and i—
However , the two forms have a slightly yet
important difference.
Consider following example:
 int a = 9;
 Printf(―%d n‖ , a++);
 Printf(―%d‖ , a);






The output would be:
9
10


But if we have:
int a=9;
printf(―%d n‖ , ++a);
printf(―%d‖ , a);



The output would be :
10
10





a++ would return the current value of a and
then increment the value of a
++a on the other hand increment the value of
a before returning the value
++or-Statement

Equivalent statements

r value

Count
value

r = count++;

r = count;
count = count + 1;

10

11

r = ++count;

count = count + 1;
r = count;

11

11

r = count--;

r = count;
count = count - 1;

10

9

r = --count;

count = count - 1;
r = count;

9

9
C operation

operator

Example

Addition

+

a+3

Subtraction

-

a–6

Multiplication

*

a*b

Division

/

a/b

modulus

%

a%x

• The division of variables of type int will always produce a variable
of type int as the result.

•

You could only use modulus (%) operation on int variables.




Assignment operators are used to combine
the ‗=‗ operator with one of the binary
arithmetic operators.
in following, c=9

operator

example

Equivalent statement

Result

+=

c += 7

c=c+7

c = 16

-=

c -= 8

c=c–8

c=1

*=

c *= 10

c = c * 10

c = 90

/=

c /= 5

c=c/5

c=1

%=

c %= 5

c=c%5

c=4





This comes into play when there is a mixed of
arithmetic operators in one statement.
Eg. x = 3*a - ++b % 3;
The rules specify which of the operators will
be evaluated first.
Precedence level

operator

Associativity

1(highest)

()

Left to right

2

Unary

Right to left

3

*/%

Left to right

4

+-

Left to right

5(lowest)

= += -= *= /= %=

Right to left


Equality operators:
operator

Meaning

==

x == y

x is equal to y

!=



example
x != y

x is not equal to y

Relational operators:
operator

example

Meaning

>

x>y

x is greater than y

<

x<y

x is less than y

>=

x >= y

x is greater than or equal to y

<=

x <= y

x is less than or equal to y






Logical operators are useful when we want to
test multiple conditions.
There are 3 types of logical operators and they
work the same way as the boolean AND,OR,NOT
operators.
&& - Logical AND
 All the conditions must be true for whole expression
to be true.
 Eg. if(a==10 && b==9 && d==1) means if
statement is true only if a=10,b=9,d=1.


|| - Logical OR
 The truth of one condition is enough to make
the whole expression true.
 Eg. if(a == 10 || b==9 || d==1) means
expression is true either a , b or d has right
value.



! - Logical NOT

 Reverse the meaning of a condition.

 Eg. if(!(a>90)) means if a is bigger than 90





The conditional operator (?:) is used to
simplify an if/else statement.
Condition ? Expression 1 : expression 2
The statement above is equivalent to:

if(condition)
expression 1
else
expression 2


This presentation exposed you the operators
used in C
◦
◦
◦
◦
◦





Arithmetic operators
Assignment operators
Equalities & relational operators
Logical operators
Conditional operators

Precedence levels come into play when there
is mixed arithmetic operators in one
statement.
Pre/pro fix-effects the result of statement.
Basic c operators

More Related Content

What's hot

BOOLEAN ALGEBRA & LOGIC GATE
BOOLEAN ALGEBRA & LOGIC GATEBOOLEAN ALGEBRA & LOGIC GATE
BOOLEAN ALGEBRA & LOGIC GATE
Ideal Eyes Business College
 
C fundamental
C fundamentalC fundamental
C fundamental
Selvam Edwin
 
Bitwise Operators in C
Bitwise Operators in CBitwise Operators in C
Bitwise Operators in C
yndaravind
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
Darshan Patel
 
Parallel Adder and Subtractor
Parallel Adder and SubtractorParallel Adder and Subtractor
Parallel Adder and Subtractor
Smit Shah
 
Boolean algebra And Logic Gates
Boolean algebra And Logic GatesBoolean algebra And Logic Gates
Boolean algebra And Logic Gates
Kumar
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
Prabhu Govind
 
System Programming Unit IV
System Programming Unit IVSystem Programming Unit IV
System Programming Unit IV
Manoj Patil
 
What is a decoder and 2 to 4 DECODER
What is a decoder and 2 to 4 DECODERWhat is a decoder and 2 to 4 DECODER
What is a decoder and 2 to 4 DECODER
safia safreen
 
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational Circuits
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational CircuitsCOMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational Circuits
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational Circuits
Vanitha Chandru
 
Operators in c language
Operators in c languageOperators in c language
Operators in c language
Amit Singh
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
Manoj Tyagi
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
Jordan Delacruz
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
Anuja Lad
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
Shobi P P
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
Himanshu Negi
 
Processor Organization
Processor OrganizationProcessor Organization
Processor Organization
Dominik Salvet
 
Binary parallel adder
Binary parallel adderBinary parallel adder
Binary parallel adder
anu surya
 
Module 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in CModule 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in C
Tushar B Kute
 
Encoder and decoder
Encoder and decoderEncoder and decoder
Encoder and decoder
Then Murugeshwari
 

What's hot (20)

BOOLEAN ALGEBRA & LOGIC GATE
BOOLEAN ALGEBRA & LOGIC GATEBOOLEAN ALGEBRA & LOGIC GATE
BOOLEAN ALGEBRA & LOGIC GATE
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Bitwise Operators in C
Bitwise Operators in CBitwise Operators in C
Bitwise Operators in C
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Parallel Adder and Subtractor
Parallel Adder and SubtractorParallel Adder and Subtractor
Parallel Adder and Subtractor
 
Boolean algebra And Logic Gates
Boolean algebra And Logic GatesBoolean algebra And Logic Gates
Boolean algebra And Logic Gates
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
 
System Programming Unit IV
System Programming Unit IVSystem Programming Unit IV
System Programming Unit IV
 
What is a decoder and 2 to 4 DECODER
What is a decoder and 2 to 4 DECODERWhat is a decoder and 2 to 4 DECODER
What is a decoder and 2 to 4 DECODER
 
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational Circuits
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational CircuitsCOMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational Circuits
COMPUTER ORGANIZATION - Logic gates, Boolean Algebra, Combinational Circuits
 
Operators in c language
Operators in c languageOperators in c language
Operators in c language
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
 
Processor Organization
Processor OrganizationProcessor Organization
Processor Organization
 
Binary parallel adder
Binary parallel adderBinary parallel adder
Binary parallel adder
 
Module 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in CModule 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in C
 
Encoder and decoder
Encoder and decoderEncoder and decoder
Encoder and decoder
 

Similar to Basic c operators

Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
Munazza-Mah-Jabeen
 
operator
operatoroperator
operator
aamirsahito
 
operator ppt.ppt
operator ppt.pptoperator ppt.ppt
operator ppt.ppt
MrSharadtechnical
 
This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptx
ranaashutosh531pvt
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
Deepak Singh
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
vishaljot_kaur
 
Operators
OperatorsOperators
Operators
jayesh30sikchi
 
C Operators
C OperatorsC Operators
C Operators
Yash Modi
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
operators.pptx
operators.pptxoperators.pptx
operators.pptx
ruchisuru20001
 
intro to differnt oper.pptx
intro to differnt oper.pptxintro to differnt oper.pptx
intro to differnt oper.pptx
ssuser5ad1571
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
Anusuya123
 
C operators ppt
C operators pptC operators ppt
C operators ppt
RajniKashyap9
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
Mohammad Imam Hossain
 
Operator in C language
Operator in C languageOperator in C language
Operator in C language
KanhaiyaSharma52
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
V.V.Vanniapermal College for Women
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
Kathirvel Ayyaswamy
 

Similar to Basic c operators (20)

Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 
operator
operatoroperator
operator
 
operator ppt.ppt
operator ppt.pptoperator ppt.ppt
operator ppt.ppt
 
This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptx
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
Operators
OperatorsOperators
Operators
 
C Operators
C OperatorsC Operators
C Operators
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
operators.pptx
operators.pptxoperators.pptx
operators.pptx
 
intro to differnt oper.pptx
intro to differnt oper.pptxintro to differnt oper.pptx
intro to differnt oper.pptx
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
C operators ppt
C operators pptC operators ppt
C operators ppt
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
Operator in C language
Operator in C languageOperator in C language
Operator in C language
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 

Basic c operators

  • 1.
  • 2.
  • 3. Arithmetic operators 1. Unary operators 2. Binary operators  Assignment operators  Equalities and Relational operators  Logical operators  Conditional operators 
  • 4.  In C , we have the following operators. operation operator initialization Addition + a+ b = c Subtraction - a-b=c Multiplication * a*b=c Division / a/b=c Increment ++ a++ Decrement __ a-- Modulus % a%b=c
  • 5.  There are two types of arithmetic operators in C: 1. Unary operators: • Operators that require only one operand 2. Binary operators: • Operators that require two operands.
  • 6. C operation operator Example Positive + a = +3 Negative - b = -a Increment ++ i++ decrement -- i-- The first assigns the positive value of 3 to a. The second assigns the negative value of a i++ is equivalent to i = i + 1. i-- is equivalent to i = i - 1. to b.
  • 7.    It is also possible to use ++i and –-i instead of i++ and i— However , the two forms have a slightly yet important difference. Consider following example:  int a = 9;  Printf(―%d n‖ , a++);  Printf(―%d‖ , a);    The output would be: 9 10
  • 8.  But if we have: int a=9; printf(―%d n‖ , ++a); printf(―%d‖ , a);  The output would be : 10 10   a++ would return the current value of a and then increment the value of a ++a on the other hand increment the value of a before returning the value
  • 9. ++or-Statement Equivalent statements r value Count value r = count++; r = count; count = count + 1; 10 11 r = ++count; count = count + 1; r = count; 11 11 r = count--; r = count; count = count - 1; 10 9 r = --count; count = count - 1; r = count; 9 9
  • 10. C operation operator Example Addition + a+3 Subtraction - a–6 Multiplication * a*b Division / a/b modulus % a%x • The division of variables of type int will always produce a variable of type int as the result. • You could only use modulus (%) operation on int variables.
  • 11.   Assignment operators are used to combine the ‗=‗ operator with one of the binary arithmetic operators. in following, c=9 operator example Equivalent statement Result += c += 7 c=c+7 c = 16 -= c -= 8 c=c–8 c=1 *= c *= 10 c = c * 10 c = 90 /= c /= 5 c=c/5 c=1 %= c %= 5 c=c%5 c=4
  • 12.    This comes into play when there is a mixed of arithmetic operators in one statement. Eg. x = 3*a - ++b % 3; The rules specify which of the operators will be evaluated first. Precedence level operator Associativity 1(highest) () Left to right 2 Unary Right to left 3 */% Left to right 4 +- Left to right 5(lowest) = += -= *= /= %= Right to left
  • 13.  Equality operators: operator Meaning == x == y x is equal to y !=  example x != y x is not equal to y Relational operators: operator example Meaning > x>y x is greater than y < x<y x is less than y >= x >= y x is greater than or equal to y <= x <= y x is less than or equal to y
  • 14.    Logical operators are useful when we want to test multiple conditions. There are 3 types of logical operators and they work the same way as the boolean AND,OR,NOT operators. && - Logical AND  All the conditions must be true for whole expression to be true.  Eg. if(a==10 && b==9 && d==1) means if statement is true only if a=10,b=9,d=1.
  • 15.  || - Logical OR  The truth of one condition is enough to make the whole expression true.  Eg. if(a == 10 || b==9 || d==1) means expression is true either a , b or d has right value.  ! - Logical NOT  Reverse the meaning of a condition.  Eg. if(!(a>90)) means if a is bigger than 90
  • 16.    The conditional operator (?:) is used to simplify an if/else statement. Condition ? Expression 1 : expression 2 The statement above is equivalent to: if(condition) expression 1 else expression 2
  • 17.  This presentation exposed you the operators used in C ◦ ◦ ◦ ◦ ◦   Arithmetic operators Assignment operators Equalities & relational operators Logical operators Conditional operators Precedence levels come into play when there is mixed arithmetic operators in one statement. Pre/pro fix-effects the result of statement.