Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views

C Programming

C programming class notes

Uploaded by

krish.xix
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

C Programming

C programming class notes

Uploaded by

krish.xix
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Introduction

In C programming, operators are vital symbols


that instruct the compiler to perform specific
operations on data. They are essential for
manipulating variables and values in a program,
enabling developers to execute calculations,
comparisons, and logical evaluations efficiently.
Types of Operators

1. Arithmetic Operator 4. Relational Operator


It performs basic mathematical operations They are used to compare two values or
on variables or values. variables and return true or false based on it.

2. Logical Operator 5. Assignment Operator


They are used to perform logical operation They are used to assign or update the value
in conditional statement. or variable.

3. Bitwise Operator 6. Ternary Operator


They perform operations on binary It is the compact way to express conditional
representation of numbers. logic or statement.
Arithmetic Operators
Addition(+)
1
Adds two operands together.

Subtraction(-)
2
Subtracts the second operand from the first.

Multiplication(*)
3 Multiplies two operands

Division(/)
4
Divides the first operand by the second.

Modulus(%)
5 Returns the remainder of the division.
Logical Operators

1. Logical AND (&&) 2. Logical OR (||) 3. Logical NOT (!)


Return true if both operands Return true if atleast one Inverts the truth value of an
are true. operands are true. operand

if (x > 0 && y > 0) if (x == 0 || y == 0) if (!(x > 0 && y > 0))


{ { {
// Both x and y // Either x or y is // Both x and y are
are positive zero greater than 0
} } }
Bitwise Operator
01
Performs a bit-by-bit AND operation on
Bitwise AND (&) two operands.

02
Performs a bit-by-bit OR operation on
Bitwise OR (|) two operands.

03
Performs a bit-by-bit XOR operation
Bitwise XOR (^) on two operands.

04 Bitwise NOT (~) Inverse all the bits of an operand.

05
Shifts the bits of an operand to the
Left Shift (<<) left.

06
Shifts the bits of an operand to the
Right Shift (>>) right.
Relational Operator
Operator Meaning Example

< Less than 5 < 10

> Greater than 10 > 5

<= Less than or equal to 5 <= 10

>= Greater than or equal to 10 >= 5

== Equal to 5 == 5

!= Not equal to 5 != 10
Assignment Operator

Simple Assignment (=)

01 Assigns the value on the right to the left


operand.

Compound Assignment

02 Combination of arithmetic operation with a


assignment.
Conditional Operator (?:)
The conditional operator in C, also known as the ternary operator, provides a
shorthand for if-else statements. It operates on three operands and allows for
compact code representation, making it more space-efficient while delivering the
same functionality as traditional if-else constructs.

// if (condition){
// result = value1;
// } else {
result = value2;
// }

result = (condition) ? value1 : value2;

If the condition is true, value1 is assigned to result. Otherwise, value2 is assigned.


Increment & Decrement Operator

1. Increment (++) 2. Decrement (--) 3. Prefix & Postfix


It increases the value of a It decreases the value of a It Increments / Decrements
variable by 1. variable by 1. first,then use the value.
It Increments / Decrements
after using the value.

// Prefix
// var = var + 1 // var = var + 1 result = ++var
// result = var // result = var result = --var

result = ++var result = --var // Postfix


result = var--
result = var++
Operator Precedence and Associativity
Precedence Level Operators Associativity
1 () Left - to - Right

2 ++ , -- (Postfix) Left - to - Right

3 + , - , ! , ~ , ++ , -- Right - to - Left

4 *,/,% Left - to - Right

5 +,- Left - to - Right

6 < , > , <= , >= Left - to - Right

7 == , != Left - to - Right

8 && Left - to - Right

9 `

10 = , += , -= , …. Right - to - Left
Conclusion
Operators are fundamental building blocks of C programming.
By understanding the different types of operators, you can
write powerful and efficient C programs.
Thank You
We appreciate your attention and hope this presentation
provided valuable insights of Operators in C programming.

You might also like