Home  >  Article  >  Backend Development  >  What does sign mean in c language?

What does sign mean in c language?

下次还敢
下次还敢Original
2024-05-07 09:06:14521browse

In C language, the sign() function returns the sign of the expression (positive, negative, or zero). Return value: 1 if the expression is positive, -1 if it is negative, and 0 if it is zero.

What does sign mean in c language?

sign means in C language

In C language, sign function Returns the sign of the expression, which can be positive, negative, or zero.

Usage

<code class="c">int sign(int n);</code>

Where:

  • n is the expression to determine the symbol.

Return value

  • If n is a positive number, return 1.
  • If n is negative, return -1.
  • If n is zero, return 0.

Example

<code class="c">int num1 = 5, num2 = -10;

printf("sign(%d) = %d\n", num1, sign(num1));
printf("sign(%d) = %d\n", num2, sign(num2));</code>

Output:

<code>sign(5) = 1
sign(-10) = -1</code>

The above is the detailed content of What does sign mean in c language?. 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