![]() |
The not-equal operator is a fundamental comparison operator in C++ represented by “!=”. It is used for making decisions in programming and is hence called a conditional operator. In this article, we will discuss how to use the Not-Equal (!=) operator in C++. Not-Equal (!=) Operator in C++The not-equal operator(!=) evaluates two values and returns a boolean value.
The not equal to the operator is a binary operator so it is used with the two operands: operand1 != operand2 It only allows for branching when both values are different and can be used to make decisions based on a given condition. How to Use the Not-Equal (!=) Operator in C++?The following examples show how can we use the not-equal operator in our C++ programs: Example 1The below example demonstrates the use of the not-equal operator in conditional statements. C++
Output
10 is not equal to 20 Explanation: In above example, we are using Not-Equal Operator (!=) that checks whether the num1 and num2 are equal or not. As 10 and 20 are not equal so the block of code inside if statement is executed and prints ” 10 is not equal to 20 “. Example 2The below example demonstrates the use of not-equal operator in loops. C++
Output
The number 6 is not present in the array. Explanation: In above example, we are checking that a target is present in array or not by using a not equal operator to loop in array until iterator i is not equal to size of array. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |