Home > Backend Development > C#.Net Tutorial > The difference between !a and a! in c language

The difference between !a and a! in c language

下次还敢
Release: 2024-05-02 17:16:01
Original
843 people have browsed it

In C language, the difference between !a and a! is: !a is a logical NOT operation, converting true values ​​into false, and false values ​​into true; and a! is a factorial operation, calculating the number a factorial.

The difference between !a and a! in c language

The difference between !a and a! in c language

Direct answer:
In C language, !a represents logical NOT operation, and a! represents factorial operation.

Detailed explanation:

  • Logical NOT operation (!a):

    • Convert true values ​​to false and false values ​​to true.
    • !0 The result is 1 (true), !1 The result is 0 (false).
  • Factorial operation (a!):

    • Calculate the factorial of the number a.
    • 5!The result is 120, which is 1 x 2 x 3 x 4 x 5.

Example:

<code class="c">int a = 5;

printf("!a = %d\n", !a); // 输出0,因为5是非0值,因此其非值为假(0)
printf("a! = %d\n", a!); // 输出120,因为5的阶乘是120</code>
Copy after login

Note:

  • The factorial operation must Performed on non-negative integers.
  • If you try to calculate the factorial of a negative number, the program will generate an error.

The above is the detailed content of The difference between !a and a! in c language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template