0% found this document useful (0 votes)
21 views28 pages

Operators New

Uploaded by

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

Operators New

Uploaded by

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

Operators in C

An operator is a symbol that tells the compiler to perform a certain


mathematical or logical operations, based on the values provided
to the operator.

C language supports a rich set of built-in operators, they are


1. Arithmetic operators
2. Assignment operators
3. Relational operators
4. Logical operators
5. Bit wise operators
6. Conditional operators (ternary operators)
7. Increment/decrement operators
8. Special operators
1.ARITHMETIC OPERATORS IN C

C Arithmetic operators are used to perform mathematical calculations


like addition, subtraction, multiplication, division and modulus in C
programs.
EXAMPLE PROGRAM FOR C ARITHMETIC OPERATORS

In this example program, two values “40” and “20” are used to perform
arithmetic operations such as addition, subtraction, multiplication,
division, modulus and output is displayed for each operation.
2.ASSIGNMENT OPERATORS IN C

In C programs, values for the variables are assigned using assignment operators.
 For example, if the value “10” is to be assigned for the variable “sum”, it can be
assigned as “sum = 10;”

There are 2 categories of assignment operators in C language. They are,


1. Simple assignment operator ( Example: = )
2. Compound assignment operators

( Example: +=, -=, *=, /=, %=, )


Sample Program
Output:
3.RELATIONAL OPERATORS IN C
Relational operators are used to find the relation between two variables. i.e. to
compare the values of two variables in a C program.
4.LOGICAL OPERATORS IN C

These operators are used to perform logical operations on the given


expressions.
5.BIT WISE OPERATORS IN C
These operators are used to perform bit operations.

Decimal values are converted into binary values which are the sequence of bits and

bit wise operators work on these bits.


BELOW ARE THE BIT-WISE OPERATORS AND THEIR NAME IN C LANGUAGE.

1. & – Bitwise AND

2. | – Bitwise OR

3. ~ – Bitwise NOT

4. ^ – XOR

5. << – Left Shift

6. >> – Right Shift


How Bitwise Operators work in C?

1. Bitwise AND operator

This operator is a binary operator which means it works on two operands.

It is represented by an ampersand sign (&).

This operator results in 1 when the values of both the bits are 1.
Bitwise OR operator

This operator is a binary operator.

It is represented by a vertical bar sign (|).

This operator results in 1 when the value of at least one bit is 1.


Bitwise NOT operator

This operator is a unary operator which means it requires only one operand.

It is also known as a bitwise complement or one’s complement operator. This operator is represented by the
tilde sign (~).

When applied on bits, this operator converts all zeroes (0’s) to ones (1’s) and vice versa.
Bitwise XOR operator

This operator is a binary operator.

It is known as XOR i.e. exclusive OR operator.

This operator is represented by ‘^’ sign.

For opposite bits it results in 1 and for the same bits it results in 0.
Left shift operator

It is represented by the ‘<<’ sign. It is used to shift all the bits to the left by a specified
number of bits.
Right shift operator

It is represented by ‘>>’ sign. It is used to shift all the bits to the right by a specified
number of bits.
6.Conditional Operators in C
7.Increment/Decrement Operators in C
Increment operators are used to increase the value of the variable by one.

Decrement operators are used to decrease the value of the variable by one in C
programs.
8.Special Operators in C

Below are some of the special operators that the C programming language
offers.

Dr.R.KARTHIKEYAN/PROFESSOR/CSE(AI&ML)/V
ARDHAMAN COLLEGE OF ENGG.

You might also like