BASICS OF C++ (OPERATORS)
Hello guys as I told you before , that along with the govt. Jobs update I will also share some information about C++ computer language. As I am also a learner so tell me about anything you find wrong in my explanation.
So, today our topic will be on operators. In coding operators plays a major role so, we need to know about them . There are many operators in c++ ,but today we will discuss about
Logical and
Conditional operators. So, let's get started.
Logical Operators :-
Logical Operators are basically of three types
1. Logical or ||
2. Logical and &&
3. Logical not !
Logical Or (||)
It basically combines two conditions and show value if any one condition is true.
Ex :- Suppose in a function we have to provide award to those students who had either 99 marks in English or 100 marks in maths . In coding we use Logical or operator.
Like
If(English==99||maths==100)
It will show name of all those students who has either 99 marks in English or 100 marks in maths . In other words we can say it will show those names who will satisfy any one of these condition.
Similarly,
(4==4||9>10)
This will show true 1 as first condition is true ;
(3<2||5>7)
This will show false as both are wrong;
Logical And (&&)
It also combines two statements as Logical or does but it shows true value only if both conditions are true .
Ex :- consider same situation as in above example but here we have a bit of change we have to provide awards to those students who have scored 99 marks in English as well as 100 marks in maths.
In this case we have to use operator that checks both conditions we write as
If(English==99&& maths==100)
In this code compiler will show only those names who satisfy both conditions.
Similarly;
(4==4&&9>15)
This will show false value as one condition is false
(9>8&&4>2)
This will show true as both conditions are true.
 |
| Difference in Logical or and Logical and operator |
Note :- This was just to show you so I just made simple so i entered these condition.
But in programming we use condition as I given example above of English and maths then that will show you output
Logical not (!)
This converse the result we get
For ex.
If we write :- 9>5 it is true but if we write
!(9>5) it will show false as there is Logical not operator used before condition.
This operator is very simple to understand.
If any problem comment . I will try to give better explanation.
Now that's were Logical Operators now next is Conditional operators:-
Conditional Operators :-
Conditional Operator is operator that store values for a particular condition. It has two values one if condition become false and one if condition is true.
General form of conditional Operator is :-
expression1 ? expression2 : expression3
Here if expression 1 evaluates to true , whole expression is the value of expression2 otherwise whole expression has value of expression3
For ex.
Result = marks>=50 'P' : 'F' ;
Here
Result = whole expression
marks>=50 = expression1
'P' = expression2
'F' = expression3
If the inputted marks will be 70 then
70>=50 it's true so result will have the value of expression2 means 'P';
If the inputted marks is 30 then
30>=50 it's false then result will have value of expression3 means 'F'
Guys hope you understand it's over for today
Next post will be about some other Logical Operators
Like ,share and comments please