- Welcome guys ,In this lecture you are going to learn a new and interesting thing .
- Believe be guys by the end of this lecture I'll assure you that , if someone ask you about Relational Operators your brain will answer - Yes I knew about it .
- Before diving into the main topic make sure that you knew about the Operators in C++ which was explained in Lecture 5 .
- Relational Operators
- As we seen in lecture 5 some of the relational operators are Relational Operators { <. >, <= , >= , ==, != }
- Don't get panic guys I'm here to explain about each and every symbols above .
- What are relational operators ???
- If you got the doubt ,continue reading....
- Relational operators are used to find out the relation between any two variables ,or any two values ,or between a value and variable.
- Don't worry now we will go to examples and explain each symbol
- { < } : I think you might know this name . Yes, it is "less then". It is used to check weather the first value is less than second or not
- Wait how we will check ?? It will say us by returning either true or false .Confused??. Don't worry you will get to know about it clearly now so continue reading .
- Eg.1., bool che = 5 < 7;
- Hey, what this bool again?? Sorry guys, I'll tell you about it .It's just a small thing .
- bool is used to give ability to it's variable to store either true or false . So in Eg1., che should store either true or false .
- Okay ,now see in example we written a statement "5 < 7" .Yes, 5 is always less than 7.
- It is true .So " 5 < 7 " returns/gives the value true and it is stored in che.
- Okay what will happen if we write bool che = 7 < 5; .Yes you are right che stores false in it because 7 is not less than 5
- { > } : I think you can guess the use of this .
- If you can't, don't worry I'll explain .It is called as greater than symbol used to check weather the first value is greater than second or not .
- Eg.,2 int fir = 98 ; int sec = 56 ; bool ans = fir > sec ;
- In the above statements fir stores 98 and sec stores 56 as per our current knowledge
- So fir is greater than sec ,yes it is true. So fir > sec return true and ans = true .
- { <= ,>= } : These are called as less than or equal to and greater than or equals to .These are works same as less than and greater than but with an extra feature.
- Extra feature : They will return true if values on both sides equal ,Don't worry if confused ,See below example.
- Eg.,3 int s1 = 10 ; int s2 = 14 ;int s3 = 10 ;
- bool ans1 = s1 <= s2 ; bool ans2 = s1 >= s2 ;bool ans3 = s1 >= s3 ;bool ans4 = s2 <= s3
- In above statements ans1 = true ,ans2 = false ,ans3 =true , ans4 = true .
- If you not understand above statement ,think for few minutes and comment in comment box still confused.
- { == } : This operator is called is equal it returns true if values on both sides are equal or it will simply returns false .
- Eg.,4 int e1 = 16 ; int e2 = 53 ;int e4 = 16 ;
- bool res1 = e1 == e2 ; bool res2 = e1 == e3;
- In above statement res1 = false because e1 is not equals to e2 ,but e1 is equals to e3 so res2 = true.
- { != } : This operator is called is not equal it returns true if values on both sides are not equal or it will simply returns false .Means it is completely opposite to == .
- Eg.,5 int e1 = 16 ; int e2 = 53 ;int e4 = 16 ;
- bool res1 = e1 != e2 ; bool res2 = e1 != e3;
- In above statement res1 = truebecause e1 is not equals to e2 ,but e1 is equals to e3 so res2 = false.
*****Don't worry if you are confused you will know everything in further concepts ,please read previous lectures too, Don't give up if you are confused . Don't Panic ,be patient we will learn everything*****
***** If you have any doubts please ask in comment box*****