Home  >  Article  >  Backend Development  >  What does != mean in c++

What does != mean in c++

下次还敢
下次还敢Original
2024-04-28 17:18:11475browse

!= operator is used to compare whether two operands are equal. Syntax: result = operand 1 != operand 2; return Boolean value: if the operands are not equal, return true; if they are equal, return false. It only works with data of the same type, e.g. comparing an integer to a string will produce an error.

What does != mean in c++

!= meaning in C

!= operator

!= is a comparison operator in C, which is used to compare whether two operands are not equal.

Syntax

<code class="cpp">结果 = 操作数1 != 操作数2;</code>

Return value

!= operator returns a Boolean value:

  • If the operands are not equal, return true.
  • If the operands are equal, return false.

Example

<code class="cpp">int num1 = 10;
int num2 = 20;

bool result = (num1 != num2);  // 结果为 true,因为 num1 和 num2 不相等

int num3 = 10;

bool result2 = (num1 != num3);  // 结果为 false,因为 num1 和 num3 相等</code>

Note

!= operator can only compare operands of the same type. For example, integers cannot be compared to strings.

The above is the detailed content of What does != mean in c++. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does / mean in c++Next article:What does / mean in c++