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. You 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 will show you how to use that operator, when to use that operator and in programs I will 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 am going to start with basics like what is operator and how to classify operators means operators can be classified into you know based on two categories like based on operations and based on that operands. So that thing I am going to discuss in this video and this video is brought to you by Unacademy.
On Unacademy 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, the best faculties will cover the entire syllabus for life sciences for CSIR net June 2021 exam.
And this batch. the classes in this batch 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 operates 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 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 unary next one is binary and ternary operator Unary means only one operand is there.
Binary means two operands. Ternary 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 unary minus. This is binary. What is the difference? That is we will see also. This is unary 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 like int 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 unary 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 we 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 types in two cases prefix and postfix. Suppose I am writing here x++ or x++x.
So this is what? This is also increment operator. This is increment operator.
But here this is postfix and this is increment 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 same 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 post fix.
So the value of this. 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'm writing y is equal to x plus plus so now in y what would be stored 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 is 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 x becomes 11 is equal to 12 and here it will be stored 12. 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. 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, 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 will 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 false and false value into true it is going to you 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 used 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 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 sizeof size of int and if you want to print this one so it will give 2 bytes or may be 4 bytes size of float it will give 4 bytes it will give size in bytes memory size in bytes so it is used to find out the size of any data type it is also you can also use it with the 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 two 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 and 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 separately coma 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 X expression should be a condition here that is a rule so now if this expression 1 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 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 some rules are there the first expression must be a condition. Second rule is either this expression 2 or this only 1 either this or this would be evaluated based on the value of expression 1. It is not that both would be evaluated only 1 and this must be a condition. So here a is 10 and b is 15. 10 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 stored? 15. If you will print print f this X then 15 would be the output. Right?
And suppose if you write here A less than B. Is it true? Yes it is true. Now the control will go to a. This expression would be evaluated.
Here we don't have any expression we just have an operand that is a value is 10. So now 10 would be assigned to x and output would be. 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 if and else. Because if else also you can convert it into 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 are going to discuss in later videos in detail. right so that's it about types of operator based on operands i hope you got all these operators if you want me to make a separate video on the stunnery 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