C_13 Operators in C - Part 1 | Unary , Binary and Ternary Operators in C | C programming Tutorials

Jenny's Lectures CS IT
23 Dec 202015:38

Summary

TLDRThis video lecture introduces operators in C programming, explaining their significance and classification. It distinguishes between unary, binary, and ternary operators with examples. The lecture covers arithmetic, relational, logical, bitwise, and assignment operators, and delves into the conditional (ternary) operator. The instructor also promotes an academy's course for CSIR NET exam preparation, offering a discount code for viewers.

Takeaways

  • πŸ“˜ The lecture series is transitioning from discussing data types to operators in the C programming language.
  • πŸ” The lecturer will provide detailed explanations of each operator, including examples and their outputs.
  • 🏫 The lecture is sponsored by an academy that offers courses for the CSIR NET exam, covering the complete syllabus in multiple batches.
  • πŸ’» The academy's life sciences batch starts on January 8th, with classes in Hindi and notes in English.
  • πŸ’° A discount code (JKL10) is offered for a paid subscription to the academy's course.
  • πŸ”’ An operator in C is defined as a symbol that directs the compiler to perform specific operations on data.
  • πŸ”‘ Operators can be classified based on the number of operands they require: unary (one), binary (two), and ternary (three).
  • πŸ”„ Unary operators include the minus sign, increment/decrement, logical NOT, address-of, and sizeof operators.
  • πŸ”„ Binary operators encompass arithmetic, relational, logical, bitwise, equality, and assignment operators.
  • πŸ”„ Ternary operators are conditional, requiring three operands and using a question mark syntax for execution.
  • πŸ“š The next video will delve into types of operators based on operations, promising an in-depth exploration of each type.

Q & A

  • What is the main focus of the lecture series?

    -The main focus of the lecture series is learning programming in C, specifically starting with operators in C after covering all the data types.

  • What will be covered in the lectures about operators?

    -The lectures will cover every type of operator in detail, with examples and programs showing how to use them, when to use them, and what output to expect.

  • What is the purpose of the operators in C?

    -Operators in C are used to manipulate variables or data, allowing mathematical or logical manipulations to be performed on the operands.

  • What is an expression in the context of C programming?

    -An expression is a sequence of operators and operands that gives a single value after processing.

  • What are the three categories of operators based on the number of operands?

    -The three categories of operators based on the number of operands are unary (one operand), binary (two operands), and ternary (three operands).

  • What is a unary operator and can you give an example?

    -A unary operator is an operator that requires only one operand. An example is the unary minus operator, which changes the sign of a number.

  • How does the increment operator work in both prefix and postfix forms?

    -The increment operator (++) can be used in prefix form (before the variable) or postfix form (after the variable). The prefix form increments the variable first, then returns the value, while the postfix form returns the value first, then increments the variable.

  • What is the logical NOT operator and what does it do?

    -The logical NOT operator (!) is used to reverse the logical state of its operand. It converts true to false and false to true.

  • What does the sizeof operator return and how is it used?

    -The sizeof operator returns the size in bytes of the operand or data type specified. It is used to find out the memory size of any data type or variable.

  • How is the ternary operator different from other operators?

    -The ternary operator is unique because it takes three operands and is also known as the conditional operator. It evaluates one of two expressions based on a condition.

  • What is the syntax for using the ternary operator?

    -The syntax for using the ternary operator is: condition ? expression_if_true : expression_if_false. It evaluates the expression_if_true if the condition is true, otherwise, it evaluates the expression_if_false.

Outlines

00:00

πŸ’» Introduction to Operators in C Programming

The paragraph introduces the concept of operators in the C programming language. It discusses the transition from learning about data types to operators, emphasizing that operators are symbols that instruct the compiler to perform specific operations on data. The speaker outlines a plan to cover all types of operators in detail, providing examples and explaining their usage within programs. The lecture series is sponsored by an academy preparing for the CSIR NET exam, and a discount code is mentioned for those interested in enrolling. The video also touches on the basics of operators, explaining them as symbols for mathematical or logical manipulations, and introduces the concept of expressions formed by a sequence of operators and operands that yield a single value after processing.

05:01

πŸ”§ Understanding Unary Operators in C

This paragraph delves into unary operators, which require only one operand. It explains the difference between unary and binary operators, using the minus sign as an example to illustrate how unary minus changes the sign of a value. The paragraph also covers increment and decrement operators, explaining their use in both prefix and postfix forms and how they affect the value of a variable. Logical NOT, address-of, and size-of operators are introduced, with examples provided to demonstrate their functionality. The explanation is designed to clarify how each unary operator manipulates a single operand to perform a specific task.

10:01

πŸ”„ Exploring Binary Operators in C

The focus of this paragraph is on binary operators, which operate on two operands. It lists various binary operators, including arithmetic, relational, logical, bitwise, and assignment operators. The paragraph aims to provide an overview before diving into detailed explanations in subsequent videos. The emphasis is on how these operators are used to perform actions on pairs of operands, such as addition, subtraction, comparison, and logical operations. The paragraph sets the stage for a deeper exploration of each binary operator's functionality and usage in C programming.

15:02

πŸ“‰ Discussing Ternary Operator and Wrapping Up

The final paragraph introduces the ternary operator, also known as the conditional operator, which requires three operands. It explains the syntax and usage of the ternary operator with examples, showing how it can be used to assign values based on a condition. The paragraph also hints at upcoming videos that will discuss operators based on operations and invites viewer feedback for a potential video on the ternary operator. The speaker concludes by summarizing the types of operators based on the number of operands and expresses a hope that viewers have understood the presented material, signaling the end of the current video.

Mindmap

Keywords

πŸ’‘Operators

Operators are symbols that instruct the compiler or computer to perform specific mathematical or logical manipulations on data. In the context of the video, operators are fundamental to programming in C, where they are used to manipulate variables or data. The script explains that operators can be classified based on the number of operands they work with, such as unary, binary, and ternary operators.

πŸ’‘Unary Operators

Unary operators are those that take a single operand. The video script uses examples like the unary minus operator, which changes the sign of a number, and increment/decrement operators, which increase or decrease a variable's value by one. These are crucial for performing simple manipulations on variables in C programming.

πŸ’‘Binary Operators

Binary operators require two operands and include arithmetic, relational, logical, and bitwise operators. The script mentions that these operators perform operations like addition, subtraction, and comparison. They are essential for creating expressions that result in a single value after processing.

πŸ’‘Ternary Operator

The ternary operator is unique as it takes three operands and is also known as the conditional operator. It is used for conditional expressions, where the result depends on a condition being true or false. The script provides an example where the value of 'x' is set to 'a' if 'a' is less than 'b', otherwise, it is set to 'b'.

πŸ’‘Operands

Operands are the values or variables on which operators act. The script explains that operators are classified based on the number of operands they use, such as unary (one operand), binary (two operands), and ternary (three operands). Understanding operands is key to grasping how expressions are formed and evaluated in C programming.

πŸ’‘Expressions

Expressions are sequences of operators and operands that yield a single value after evaluation. The video script gives an example of an expression 'a = 5 + 5', where '5' and '5' are operands, '+' is an operator, and 'a' is a variable that stores the result of the expression after processing.

πŸ’‘Increment and Decrement

Increment (++) and decrement (--) operators are unary operators that increase or decrease a variable's value by one. The script distinguishes between prefix and postfix usage, showing how the value of a variable 'x' changes depending on whether the increment/decrement operator is used before or after the variable in an expression.

πŸ’‘Logical NOT

The logical NOT operator is a unary operator that inverts the truth value of its operand. If the operand is true, it returns false; if false, it returns true. The script uses this operator in conditional statements to demonstrate how it can reverse the outcome of a comparison.

πŸ’‘Address Of

The address-of operator (&) is used to obtain the memory address of an operand. While the script does not provide an explicit example, it mentions that this operator is used with pointers and functions like 'scanf', which require the memory address to store or access data.

πŸ’‘Size Of

The sizeof operator is used to determine the size in bytes of a data type or variable. The script explains that it can be used with data types like 'int' or 'float' to understand how much memory they occupy, or with variables to find out their size in memory.

πŸ’‘Conditional Expression

A conditional expression is formed using the ternary operator to make a decision based on a condition. The script illustrates this with an example where the value of 'x' depends on whether 'a' is less than 'b'. This concept is central to the video's explanation of the ternary operator and its application in C programming.

Highlights

The lecture series transitions from discussing data types to operators in C programming.

Every operator in C will be discussed in detail with examples and programs.

Operators are symbols that tell the compiler what operation to perform on data.

Operators can be classified based on the number of operands they use.

Unary operators require only one operand, such as the unary minus and increment/decrement operators.

The unary minus operator changes the sign of a number, while the binary minus operator performs subtraction.

Increment and decrement operators can be used as prefix or postfix, affecting the result.

The logical NOT operator inverts the truth value of an operand.

The address-of operator retrieves the memory address of an operand.

The sizeof operator returns the size in bytes of a data type or variable.

Binary operators use two operands and include arithmetic, relational, logical, and bitwise operators.

The ternary operator is a conditional operator that requires three operands.

The ternary operator is used to form conditional expressions, similar to if-else statements.

An example of the ternary operator is provided, demonstrating its usage with variables a and b.

The next video will discuss types of operators based on operations.

The lecture is sponsored by an academy preparing for the CSIR NET exam, offering a comprehensive course with a discount code.

The academy's course covers the entire syllabus for the CSIR NET June 2021 exam, starting from January 8th.

Transcripts

play00:00

in the series of learning programming in

play00:01

c in previous lecture i have discussed

play00:03

character data type means we are done

play00:05

with all the data types we have

play00:06

discussed all data types

play00:08

now from this lecture i am going to

play00:09

start operators in c we will be

play00:11

discussing every operator every type of

play00:13

operator in detail

play00:14

with proper examples or you can say with

play00:16

programs like i'll show you how to use

play00:18

that operator when to use that operator

play00:20

and

play00:20

in programs i'll show you and what you

play00:22

will get output

play00:24

right what output you will get if you

play00:26

are using that operator

play00:27

so in this video i'm going to start with

play00:30

basics like what is operator and um

play00:32

how to classify operators means

play00:34

operators can be classified into

play00:35

you know based on two categories like

play00:37

based on operations and based on

play00:40

uh that operands so that thing i am

play00:42

going to discuss in this video

play00:44

and this video is brought to you by an

play00:45

academy on an academy multiple batches

play00:48

are going on for

play00:49

csir ugc net june 2021

play00:54

so if you are planning to prepare if you

play00:56

are planning to appear for csir net exam

play00:59

in june 2021

play01:00

you can go for it they are going to

play01:02

cover the complete syllabus

play01:04

and one batch is going to be started

play01:06

from 8th of january

play01:08

that is for life sciences in this batch

play01:11

their best faculties will cover the

play01:14

entire syllabus

play01:15

for life sciences for csir net june 2021

play01:19

exam

play01:20

and this batch the classes in dispatch

play01:23

classes would be conducted in hindi

play01:25

and they'll also provide you notes and

play01:26

the content they'll provide the notes

play01:28

they'll provide you in

play01:29

english language right and this is you

play01:32

can say the paid subscription because

play01:34

they are going to cover the entire

play01:36

syllabus you will get

play01:38

complete course a structured course and

play01:41

if you use the code jkl10 you will get

play01:44

10 discount on your paid subscription

play01:47

so if you are interested you can go for

play01:49

it all the details and the link

play01:51

as well as the referral code i'll put in

play01:53

the description box of this video

play01:55

you can go and check out you just have

play01:57

to download an academy app and you have

play01:58

to

play01:59

get the subscription of that course

play02:01

right now let us discuss

play02:03

what are operators see operator is it's

play02:06

you can say just a symbol

play02:08

which tells the compiler or which tells

play02:10

the computer

play02:11

which operation has to perform on the

play02:13

data or you can say

play02:14

which tells the computer which

play02:17

mathematical

play02:18

or you can say logical manipulation is

play02:20

to be done

play02:21

like many operators are there plus minus

play02:24

divide

play02:24

logical and logical or relational

play02:26

operators many operators are there

play02:28

so let us take this example this is what

play02:30

an operator it is a symbol

play02:32

so it is going to tell the compiler that

play02:35

it has to perform

play02:36

plus operation plus operation means if

play02:37

you will give the value 1

play02:39

and 2 then output would be 3 and if you

play02:42

write here minus it means compiler will

play02:43

come to know that it has to perform

play02:45

minus

play02:46

that minus operation or based on these

play02:48

data given this data is what this is

play02:50

what

play02:50

operands this is what operator now you

play02:53

can say

play02:54

operator is what operators are basically

play02:57

used to

play02:57

manipulate you can say variables or data

play03:01

in c language i'm going to discuss all

play03:03

the operators in the context of c

play03:04

language only right

play03:06

and with the help of operators variables

play03:08

and constant or you can say with the

play03:09

help of operators and operands in

play03:11

expression is to be formed so you can

play03:13

say what

play03:14

expression is a sequence of operators

play03:16

and operands

play03:17

which gives a single value after

play03:19

processing suppose i am taking like this

play03:22

a is equal to 5 plus

play03:25

5 so this is what an expression

play03:28

here 5 5 these are what operands

play03:32

plus and equal to this is operator a is

play03:35

what

play03:36

variable and after processing it will

play03:38

give

play03:39

single value so after processing it will

play03:41

give what 10 that would be assigned to

play03:43

this variable so this is what an

play03:45

expression right now

play03:47

types of operators types of operators

play03:50

based on operands and types of operators

play03:53

based on operations

play03:55

two categories are there so here i am

play03:58

going to discuss types of operators

play04:01

based on

play04:01

operands number of operands so there are

play04:04

three categories

play04:05

three types unity next one is binary and

play04:09

ternary operator

play04:13

unary means only one operand is there

play04:16

binary means two operands ten array

play04:19

means three operands

play04:20

now what are these unary operators

play04:24

this is unary minus see this minus is

play04:27

different

play04:28

from binary minus here also we have plus

play04:30

minus that is minus

play04:31

this is unity minus this is binary what

play04:34

is the difference that is we will see

play04:36

also this is unity minus unary minus

play04:40

increment decrement operator

play04:43

logical not operator this is logical not

play04:46

this is

play04:47

address of operator and this is size of

play04:49

operator

play04:50

so these operators required only one

play04:53

operand

play04:53

only one operand now what is this unary

play04:56

minus it is going to change

play04:58

the value means if positive value then

play05:00

it is going to change that value to

play05:02

negative

play05:02

if negative then positive suppose i am

play05:05

writing here

play05:06

uh like in a and b

play05:09

and i am taking a is equal to if you

play05:11

write like this

play05:13

a value 5 b value 10 and c is equal to a

play05:15

plus b but here

play05:16

we have used unity minus operator it

play05:19

means the value of this is not 10 this

play05:21

is minus 10 and this is what 5 so output

play05:24

would be minus 5

play05:26

right and if you write like this a is

play05:28

equal to suppose i am writing here minus

play05:30

b

play05:31

b is what 10 but this is preceded by

play05:33

minus sign unary minus so that that is

play05:36

minus 10 and this value would be

play05:37

assigned

play05:38

to variable a now a will becomes minus

play05:41

10

play05:42

so this is different from that binary

play05:45

minus operator

play05:46

right next is increment and decrement

play05:49

operator

play05:50

this increment and decrement operator we

play05:52

can use in two

play05:53

ah types in two cases prefix and

play05:57

postfix suppose i am writing here x

play06:00

plus plus or plus plus

play06:03

x so this is what this is also increment

play06:07

operator this is increment operator

play06:09

but here this is postfix and this is

play06:12

prefix because i am writing this one

play06:15

after variable means post

play06:17

before variable means pre

play06:20

and the result is also different it's

play06:22

not like that this will give save this

play06:24

and this will give same result see

play06:26

if you are writing here this one x plus

play06:28

plus and suppose here i am writing

play06:30

see x plus plus means here x plus

play06:34

1 x is equal to x plus 1 right

play06:37

now this is what after this variable

play06:39

means postfix

play06:40

so the value of this x would be altered

play06:44

after the execution of this line y is 10

play06:47

here

play06:48

space would be allocated to y 10 one

play06:51

variable is x

play06:52

memory allocation 11 would be stored

play06:54

here now i am writing y is equal to x

play06:57

plus plus so now in y what would be

play06:59

store

play07:00

you will say x plus plus means 11 plus 1

play07:03

12 would be stored here

play07:04

no but here 11 would be stored because

play07:07

this is post

play07:10

first value see you can say right after

play07:12

equal to we have x

play07:13

x value is 11 11 would be stored here

play07:16

and plus plus s

play07:18

after this variable so after execution

play07:21

of this statement

play07:22

now x value will be 12

play07:26

but y is 11 so output of y is 11 now

play07:29

output of this is 12

play07:30

i hope you got my point and if you write

play07:32

here

play07:33

plus plus x here

play07:37

the value of x would be altered before

play07:39

execution of this line

play07:41

now here here x becomes 11 is equal to

play07:44

12

play07:45

and here it will be stored 12

play07:48

right here also we have now plus plus x

play07:51

means x is also updated that is

play07:53

12 now y value would be 12 and x value

play07:56

would be

play07:56

12. because here plus plus is before

play07:59

this

play08:00

x so first of all x would be incremented

play08:04

that would be stored in y right so that

play08:06

is why

play08:07

the y output is 12 and same

play08:11

minus minus is what minus minus means

play08:14

minus minus x x minus minus this is pre

play08:16

this is post

play08:17

it means also x uh what x minus 1 and x

play08:20

minus

play08:21

1 right same rule will be applied

play08:24

in minus minus also as in plus plus

play08:26

right now we'll be discussing these

play08:28

operators in detail

play08:29

one by one in separate video this is

play08:31

just an overview i hope you got my point

play08:33

what is plus plus and

play08:34

what is minus minus here plus plus it is

play08:36

taking only one operand that is why it

play08:38

is unary operator

play08:39

this is also taking only one operand

play08:41

only x

play08:43

right next is logical not

play08:46

it is it is going to convert true value

play08:49

into force and false value into true

play08:51

it is going to i know reserve this

play08:54

logical state of any operand

play08:56

now suppose if i am writing here

play09:00

suppose this condition and x and y value

play09:03

are this one

play09:04

so x is 11 greater than y

play09:07

10 11 is greater than 10 this is true

play09:10

but you have used logical not

play09:14

it means it will return false

play09:18

right now if suppose i am writing here

play09:23

y greater than x so here

play09:26

y is equal to 10 greater than x 11

play09:29

is 10 greater than 11 no so this

play09:32

expression will give what

play09:33

false value but you have use logical not

play09:37

that is why it will give true

play09:41

i hope you got why this logical not what

play09:45

does that mean right next is address of

play09:48

operator it is going to retrieve

play09:50

the receive or you can say fetch the

play09:51

address of any operand from memory

play09:54

this operand we will use in scanner

play09:56

function we generally use or when we

play09:57

will use pointers

play09:59

at that time this operator we are going

play10:01

to use

play10:02

next is sizeof will give you can say

play10:05

size of whatever value

play10:07

you you are given here whatever data

play10:08

type suppose you are giving a data type

play10:10

here

play10:11

size of int

play10:14

and if you want to print this one so it

play10:16

will give 2 bytes or maybe 4 bytes

play10:19

size of float it will give 4 bytes it

play10:21

will give

play10:22

size and bytes memory size in bytes so

play10:25

it is used to find out the size of any

play10:27

data type

play10:28

or it is also you can also use it with a

play10:30

variable also here you can also write

play10:32

any variable

play10:33

if you are writing here like suppose int

play10:36

a

play10:37

and you can find out size of a that will

play10:40

give

play10:40

a is what type is what integer so it

play10:43

will give size

play10:44

2 bytes right so all these operators

play10:48

we are using with only single operand

play10:51

that is why these are known as

play10:52

unary operators next is binary operators

play10:56

here we are going to use two operands

play10:59

like in plus minus divide

play11:00

many type of binary operators are there

play11:03

just let me just write down the list

play11:05

here

play11:05

so these are some binary operators we

play11:07

are going to perform these operators on

play11:09

two operands

play11:09

arithmetic all the plus minus divide

play11:13

into and that modulo relational less

play11:15

than equal to less than equal to greater

play11:17

than equal to logical and logical or

play11:18

bitwise operator bitwise end bitwise or

play11:20

left shift right shift bitwise xor and

play11:23

bitwise negation

play11:25

equality operator also and not equal

play11:27

operator also this you can include in

play11:29

relational also if you are not

play11:30

specifying it uh separately

play11:32

comma operator assignment operator also

play11:35

so all these operators one by one we are

play11:37

going to discuss in detail

play11:39

in separate videos because this video

play11:41

would be lengthy if i am going to

play11:42

discuss

play11:43

these operators right next is what

play11:46

ternary operator

play11:49

ternary means it requires three operands

play11:52

it is also known as conditional operator

play11:55

so here

play11:56

we are using this question mark and

play11:59

these columns now how the syntax of

play12:02

using ternary operator is what

play12:04

here we are writing some expression

play12:06

expression means you can say sequence of

play12:08

operands and operators

play12:10

that after processing give a single

play12:11

result so

play12:13

if expression after the processing of

play12:15

expression 1

play12:16

if expression 1 is true first

play12:20

first would be what condition first

play12:23

expression should be a condition here

play12:26

that is a rule

play12:27

so now if this expression one if this

play12:30

condition is true

play12:32

then this one

play12:35

this expression would be evaluated and

play12:37

it will give you result

play12:39

whatever result you will get after

play12:40

evaluating expression 2 that would be

play12:42

output

play12:43

if expression 1 is false then

play12:47

control will go in expression 3 this

play12:50

expression would be evaluated and

play12:52

it will give you the result let us take

play12:54

one example

play12:55

uh if i am writing here this is suppose

play12:58

an example a value is 10 b value is 15

play13:00

so now this is expression 1

play13:02

this is second this is third first of

play13:04

all this expression would be evaluated

play13:06

some rules are for this for some rules

play13:09

are there the first expression must be a

play13:11

condition

play13:12

second rule is either this expression 2

play13:15

or this

play13:16

only one either this or this would be

play13:19

evaluated

play13:20

based on the value of expression one

play13:23

it is not that both would be evaluated

play13:26

only one

play13:27

and this must be a condition so here a

play13:29

is ten and b is fifteen

play13:32

ten greater than 15 is it true or false

play13:34

it is false

play13:35

so now this expression control will go

play13:38

here

play13:39

at b now b value is what 15 so in x what

play13:43

value would be store

play13:45

15 if you will print printf this x then

play13:48

15 would be the output

play13:50

right and suppose if you write here a

play13:53

less than b

play13:54

now is it true yes it is true now

play13:59

the control will go to a this expression

play14:01

would be evaluated here we do not have

play14:03

any expression we just have any of an

play14:05

operand that is a value is 10

play14:06

so now 10 would be assigned to x and

play14:10

output would be 10. so this is what

play14:12

ternary operator or you can say

play14:13

condition

play14:14

you can use a ternary operator to form a

play14:16

conditional expression

play14:18

and you can use this one conditional

play14:20

expression conditional operator

play14:23

in place of effects

play14:27

because if else also you can convert it

play14:30

into if

play14:30

if else this statement if

play14:34

a less than b you can

play14:37

say x is equal to a

play14:41

and else

play14:44

x is equal to b that's it

play14:48

if a is less than b means if this is

play14:50

true

play14:51

then a value would be assigned same if

play14:54

this is true then

play14:55

a is going to be performed and

play14:58

if this is false then control will go

play15:00

here and this expression is going to be

play15:02

evaluated

play15:03

same here meaning of this and if else

play15:06

statement is same so you can use

play15:08

this conditional operator this statement

play15:11

rather than if else if else we will we

play15:12

are going to discuss

play15:14

in later videos in detail right so

play15:16

that's it about types of operator based

play15:18

on operands

play15:19

uh i hope you go to all these operators

play15:21

if you want me to make a separate video

play15:23

on the stunner operator in more detail

play15:25

then you can tell me in the comment box

play15:26

so in next video i'm going to discuss

play15:28

types of operator based on

play15:30

operations so now i'll see you in the

play15:31

next video till then bye bye take care

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
C ProgrammingOperatorsData TypesCoding TutorialCSIR NETProgramming BasicsLogical OperatorsArithmeticEducational ContentTechnical LearningProgramming Course