Home > Backend Development > C++ > body text

In c++! How to use

下次还敢
Release: 2024-04-26 18:45:24
Original
786 people have browsed it

The exclamation point (!) in C represents a logical NOT operation, which inverts the Boolean value: if the value is true, return false; if the value is false, return true.

In c++! How to use

Exclamation mark (!) usage in C

In C, the exclamation mark (!) operator represents logic Not operation. Its function is to invert a Boolean value (true or false).

Syntax:

<code class="cpp">!expression</code>
Copy after login

Among them, expression is the Boolean expression to be inverted.

Return value:

This operator returns a Boolean value, indicating the result of the inversion of the expression. Specifically:

  • If expression is true, returns false.
  • Returns true if expression is false.

Example:

<code class="cpp">bool isTrue = true;
bool isFalse = false;

bool notTrue = !isTrue; // false
bool notFalse = !isFalse; // true</code>
Copy after login

Other usages:

In addition to the logical NOT operation, the exclamation point is also used in C It has the following usage:

  • Destructor prefix: Adding an exclamation mark before the destructor declaration indicates that the function is a virtual destructor.
  • Throw an exception: The exclamation mark can be used in the throw statement to throw an exception object.
  • Macro operations: You can use macro operators with exclamation points to perform macro expansion.

The above is the detailed content of In c++! How to use. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!