C_13 Operators in C - Part 1 | Unary , Binary and Ternary Operators in C | C programming Tutorials
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
💻 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.
🔧 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.
🔄 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.
📉 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
💡Unary Operators
💡Binary Operators
💡Ternary Operator
💡Operands
💡Expressions
💡Increment and Decrement
💡Logical NOT
💡Address Of
💡Size Of
💡Conditional Expression
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
in the series of learning programming in
c in previous lecture i have discussed
character data type means we are done
with all the data types we have
discussed all data types
now from this lecture i am going to
start operators in c we will be
discussing every operator every type of
operator in detail
with proper examples or you can say with
programs like i'll show you how to use
that operator when to use that operator
and
in programs i'll show you and what you
will get output
right what output you will get if you
are using that operator
so in this video i'm going to start with
basics like what is operator and um
how to classify operators means
operators can be classified into
you know based on two categories like
based on operations and based on
uh that operands so that thing i am
going to discuss in this video
and this video is brought to you by an
academy on an academy multiple batches
are going on for
csir ugc net june 2021
so if you are planning to prepare if you
are planning to appear for csir net exam
in june 2021
you can go for it they are going to
cover the complete syllabus
and one batch is going to be started
from 8th of january
that is for life sciences in this batch
their best faculties will cover the
entire syllabus
for life sciences for csir net june 2021
exam
and this batch the classes in dispatch
classes would be conducted in hindi
and they'll also provide you notes and
the content they'll provide the notes
they'll provide you in
english language right and this is you
can say the paid subscription because
they are going to cover the entire
syllabus you will get
complete course a structured course and
if you use the code jkl10 you will get
10 discount on your paid subscription
so if you are interested you can go for
it all the details and the link
as well as the referral code i'll put in
the description box of this video
you can go and check out you just have
to download an academy app and you have
to
get the subscription of that course
right now let us discuss
what are operators see operator is it's
you can say just a symbol
which tells the compiler or which tells
the computer
which operation has to perform on the
data or you can say
which tells the computer which
mathematical
or you can say logical manipulation is
to be done
like many operators are there plus minus
divide
logical and logical or relational
operators many operators are there
so let us take this example this is what
an operator it is a symbol
so it is going to tell the compiler that
it has to perform
plus operation plus operation means if
you will give the value 1
and 2 then output would be 3 and if you
write here minus it means compiler will
come to know that it has to perform
minus
that minus operation or based on these
data given this data is what this is
what
operands this is what operator now you
can say
operator is what operators are basically
used to
manipulate you can say variables or data
in c language i'm going to discuss all
the operators in the context of c
language only right
and with the help of operators variables
and constant or you can say with the
help of operators and operands in
expression is to be formed so you can
say what
expression is a sequence of operators
and operands
which gives a single value after
processing suppose i am taking like this
a is equal to 5 plus
5 so this is what an expression
here 5 5 these are what operands
plus and equal to this is operator a is
what
variable and after processing it will
give
single value so after processing it will
give what 10 that would be assigned to
this variable so this is what an
expression right now
types of operators types of operators
based on operands and types of operators
based on operations
two categories are there so here i am
going to discuss types of operators
based on
operands number of operands so there are
three categories
three types unity next one is binary and
ternary operator
unary means only one operand is there
binary means two operands ten array
means three operands
now what are these unary operators
this is unary minus see this minus is
different
from binary minus here also we have plus
minus that is minus
this is unity minus this is binary what
is the difference that is we will see
also this is unity minus unary minus
increment decrement operator
logical not operator this is logical not
this is
address of operator and this is size of
operator
so these operators required only one
operand
only one operand now what is this unary
minus it is going to change
the value means if positive value then
it is going to change that value to
negative
if negative then positive suppose i am
writing here
uh like in a and b
and i am taking a is equal to if you
write like this
a value 5 b value 10 and c is equal to a
plus b but here
we have used unity minus operator it
means the value of this is not 10 this
is minus 10 and this is what 5 so output
would be minus 5
right and if you write like this a is
equal to suppose i am writing here minus
b
b is what 10 but this is preceded by
minus sign unary minus so that that is
minus 10 and this value would be
assigned
to variable a now a will becomes minus
10
so this is different from that binary
minus operator
right next is increment and decrement
operator
this increment and decrement operator we
can use in two
ah types in two cases prefix and
postfix suppose i am writing here x
plus plus or plus plus
x so this is what this is also increment
operator this is increment operator
but here this is postfix and this is
prefix because i am writing this one
after variable means post
before variable means pre
and the result is also different it's
not like that this will give save this
and this will give same result see
if you are writing here this one x plus
plus and suppose here i am writing
see x plus plus means here x plus
1 x is equal to x plus 1 right
now this is what after this variable
means postfix
so the value of this x would be altered
after the execution of this line y is 10
here
space would be allocated to y 10 one
variable is x
memory allocation 11 would be stored
here now i am writing y is equal to x
plus plus so now in y what would be
store
you will say x plus plus means 11 plus 1
12 would be stored here
no but here 11 would be stored because
this is post
first value see you can say right after
equal to we have x
x value is 11 11 would be stored here
and plus plus s
after this variable so after execution
of this statement
now x value will be 12
but y is 11 so output of y is 11 now
output of this is 12
i hope you got my point and if you write
here
plus plus x here
the value of x would be altered before
execution of this line
now here here x becomes 11 is equal to
12
and here it will be stored 12
right here also we have now plus plus x
means x is also updated that is
12 now y value would be 12 and x value
would be
12. because here plus plus is before
this
x so first of all x would be incremented
that would be stored in y right so that
is why
the y output is 12 and same
minus minus is what minus minus means
minus minus x x minus minus this is pre
this is post
it means also x uh what x minus 1 and x
minus
1 right same rule will be applied
in minus minus also as in plus plus
right now we'll be discussing these
operators in detail
one by one in separate video this is
just an overview i hope you got my point
what is plus plus and
what is minus minus here plus plus it is
taking only one operand that is why it
is unary operator
this is also taking only one operand
only x
right next is logical not
it is it is going to convert true value
into force and false value into true
it is going to i know reserve this
logical state of any operand
now suppose if i am writing here
suppose this condition and x and y value
are this one
so x is 11 greater than y
10 11 is greater than 10 this is true
but you have used logical not
it means it will return false
right now if suppose i am writing here
y greater than x so here
y is equal to 10 greater than x 11
is 10 greater than 11 no so this
expression will give what
false value but you have use logical not
that is why it will give true
i hope you got why this logical not what
does that mean right next is address of
operator it is going to retrieve
the receive or you can say fetch the
address of any operand from memory
this operand we will use in scanner
function we generally use or when we
will use pointers
at that time this operator we are going
to use
next is sizeof will give you can say
size of whatever value
you you are given here whatever data
type suppose you are giving a data type
here
size of int
and if you want to print this one so it
will give 2 bytes or maybe 4 bytes
size of float it will give 4 bytes it
will give
size and bytes memory size in bytes so
it is used to find out the size of any
data type
or it is also you can also use it with a
variable also here you can also write
any variable
if you are writing here like suppose int
a
and you can find out size of a that will
give
a is what type is what integer so it
will give size
2 bytes right so all these operators
we are using with only single operand
that is why these are known as
unary operators next is binary operators
here we are going to use two operands
like in plus minus divide
many type of binary operators are there
just let me just write down the list
here
so these are some binary operators we
are going to perform these operators on
two operands
arithmetic all the plus minus divide
into and that modulo relational less
than equal to less than equal to greater
than equal to logical and logical or
bitwise operator bitwise end bitwise or
left shift right shift bitwise xor and
bitwise negation
equality operator also and not equal
operator also this you can include in
relational also if you are not
specifying it uh separately
comma operator assignment operator also
so all these operators one by one we are
going to discuss in detail
in separate videos because this video
would be lengthy if i am going to
discuss
these operators right next is what
ternary operator
ternary means it requires three operands
it is also known as conditional operator
so here
we are using this question mark and
these columns now how the syntax of
using ternary operator is what
here we are writing some expression
expression means you can say sequence of
operands and operators
that after processing give a single
result so
if expression after the processing of
expression 1
if expression 1 is true first
first would be what condition first
expression should be a condition here
that is a rule
so now if this expression one if this
condition is true
then this one
this expression would be evaluated and
it will give you result
whatever result you will get after
evaluating expression 2 that would be
output
if expression 1 is false then
control will go in expression 3 this
expression would be evaluated and
it will give you the result let us take
one example
uh if i am writing here this is suppose
an example a value is 10 b value is 15
so now this is expression 1
this is second this is third first of
all this expression would be evaluated
some rules are for this for some rules
are there the first expression must be a
condition
second rule is either this expression 2
or this
only one either this or this would be
evaluated
based on the value of expression one
it is not that both would be evaluated
only one
and this must be a condition so here a
is ten and b is fifteen
ten greater than 15 is it true or false
it is false
so now this expression control will go
here
at b now b value is what 15 so in x what
value would be store
15 if you will print printf this x then
15 would be the output
right and suppose if you write here a
less than b
now is it true yes it is true now
the control will go to a this expression
would be evaluated here we do not have
any expression we just have any of an
operand that is a value is 10
so now 10 would be assigned to x and
output would be 10. so this is what
ternary operator or you can say
condition
you can use a ternary operator to form a
conditional expression
and you can use this one conditional
expression conditional operator
in place of effects
because if else also you can convert it
into if
if else this statement if
a less than b you can
say x is equal to a
and else
x is equal to b that's it
if a is less than b means if this is
true
then a value would be assigned same if
this is true then
a is going to be performed and
if this is false then control will go
here and this expression is going to be
evaluated
same here meaning of this and if else
statement is same so you can use
this conditional operator this statement
rather than if else if else we will we
are going to discuss
in later videos in detail right so
that's it about types of operator based
on operands
uh i hope you go to all these operators
if you want me to make a separate video
on the stunner operator in more detail
then you can tell me in the comment box
so in next video i'm going to discuss
types of operator based on
operations so now i'll see you in the
next video till then bye bye take care
5.0 / 5 (0 votes)