0% found this document useful (0 votes)
16 views

C Lecture 4 Part 2

Operators are symbols that represent mathematical, relational, logical, or other operations on operands. There are various types of operators in C including arithmetic, relational, logical, assignment, and others. Arithmetic operators perform mathematical operations like addition, subtraction, multiplication, and division on operands. Binary arithmetic operators operate on two operands while unary operators operate on a single operand and can increment, decrement, or negate a value.

Uploaded by

Gagan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

C Lecture 4 Part 2

Operators are symbols that represent mathematical, relational, logical, or other operations on operands. There are various types of operators in C including arithmetic, relational, logical, assignment, and others. Arithmetic operators perform mathematical operations like addition, subtraction, multiplication, and division on operands. Binary arithmetic operators operate on two operands while unary operators operate on a single operand and can increment, decrement, or negate a value.

Uploaded by

Gagan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Operators – Arithmetic

Operators

1
Operator

• Operators are symbols that represent operations to be performed on one or


more operands.

• Operators can be defined as the symbols that help us to perform specific


mathematical, relational, bitwise, conditional, or logical computations on
operands.

• There are various operators in the C programming language such as


Arithmetic Operators, Relational Operators, Shift Operators, Logical
Operators, Bitwise Operators, Ternary or Conditional Operators, and
Assignment Operators.

2
3
Arithmetic Operators

4
Arithmetic operator

• Arithmetic Operator is used to perform mathematical operations such as


addition, subtraction, multiplication, division, modulus, etc., on the given
operands.

• For example: 5 + 3 = 8, 5 - 3 = 2, 2 * 4 = 8, etc. are the examples of


arithmetic operators.

• Arithmetic operators are of two types:

i. Binary Operator

ii. Unary Operator

5
Binary Operator

• Operators that operate or work with two operands are binary operators.

• Binary operators discussed are


i. Addition(+)
ii. Subtraction(-)
iii. Multiplication(*)
iv. Division(/)
v. Modulo(%)

6
Addition ( + )

• Adds two operands.

• Adds left operand to right operand.

Example program:

7
Subtraction ( - ) :

• Subtracts the right operand from the left operand.

Example program:

8
Multiplication ( * ):

• Multiplies two operands.

Example program:

9
Division ( / ):

• Divides the left operand by the right operand.

Example program:

10
Modulo ( % ):

• Returns the remainder of the division of the left operand by the right
operand.

Example program:

11
Unary Operator:

• A unary operator operates on a single operand, and it can be used to


perform various operations such as incrementing/decrementing a
value, negating a value, or referencing memory.

• Unary operators discussed are


i. Unary minus(-)
ii. Increment(++)
iii. Decrement(- -)
iv. NOT(!)
v. Address of operator(&)

12
Unary minus( - ):

• The unary minus operator (-) is a mathematical operator that negates


the value of its operand.
• In simpler terms, it changes the sign of a numeric value from positive
to negative or from negative to positive. The unary minus is a unary
operator because it operates on a single operand.
Example program:

13
Increment( ++ ):
• The increment operator (++) is a unary operator that is used to increase
the value of its operand by 1.
• The increment operator can be applied to variables of numeric data
types such as integers and floating-point numbers.
Example program

It can be classified as two types: Pre-increment & Post-increment


14
Pre-Increment:
A pre-increment operator is used to increment the value of a variable
before using it in an expression.

Post-Increment:
A post-increment operator is used to increment the value of the variable after
executing the expression completely in which post-increment is used.

15
Decrement( -- ):
• The decrement operator (--) is a unary operator in C that is used to
decrease the value of its operand by 1.
• The decrement operator can be applied to variables of numeric data
types such as integers and floating-point numbers.
Example program:

It can be classified as two types: Pre-decrement & Post-decrement


16
Pre-Decrement:
The pre-decrement operator decreases the value of the variable
immediately when encountered.

Post-Decrement:
The post-decrement happens when the decrement operator is used as
the suffix of the variable.

17

You might also like