C++ || Operators with c++
Programming codester
Operators with c++:
In the previous tutorial we learnt about arithmetic and assignment operator with c++.
Now let's learn other operators!
We already know there are six types of operators!
Now let's learn about Logical operator, Bitwise operator, Relational operator, and other operators.
1.logical operators:
Logical operators are used to check whether an expression is true or false. If the expression is true, it returns 1 whereas if the expression is false, it returns 0.
Operator | Example | Meaning |
&& | expression1 && expression2 | Logical AND. |
|| | expression1 || expression2 | Logical OR. |
! | ! expression | Logical NOT. |
In C++, logical operators are commonly used in decision making. To further understand the logical operators, let's see the following examples,
OUTPUT:
2. Relational Operator:
Relational operator is also known as comparison operator.
Comparison operators are used to compare two values (or variables). This is important in programming, because it helps us to find answers and make decisions.
The return value of a comparison is either 1 or 0, which means true (1) or false (0). These values are known as Boolean values, and you will learn more about them in the Booleans and If. Else chapter.
In the following example, we use the greater than operator (>) to find out if 5 is greater than 3:
A list of all comparison operators:
Operator | Name | Example |
== | Equal to | x == y |
!= | Not equal | x! = y |
> | Greater than | x > y |
< | Less than | x < y |
>= | Greater than or equal to | x >= y |
<= | Less than or equal to | x <= y |
C tutorials:
TODAYS QUESTION: What is #include <stdio.h>?
a) Preprocessor directive
b) Inclusion directive
c) File inclusion directive
d) None of the mentioned
Ans is A
Thank you for your support!
Learn and explore!
Comments
Post a Comment