Home > Backend Development > C++ > body text

What does != mean in c++

下次还敢
Release: 2024-04-28 17:18:11
Original
524 people have browsed it

!= 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>
Copy after login

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>
Copy after login

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!

Related labels:
c++
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template