In C language, the sign macro is used to determine the sign of an integer or floating point number, returning 1 (positive), 0 (zero), or -1 (negative). It has the following usage: Parameter x: the value to be checked Parameter type: the data type of x (int, long, long long or float, double, long double)
#"The meaning of sign
in c
In C language, sign
is a preprocessing macro used to determine an integer or Whether the value of a floating point number is positive, negative, or zero.
How to usesign
sign
The macro has two parameters:
x
: The integer or floating point number to be checked #type
: Specifies the data type of x
, which can be int
, long
, long long
or float
, double
, long double
# The ##sign macro will return the following values:
:
x is positive
:
x is 0
:
x is negative
Example
The following example demonstrates the use of thesign macro:
<code class="c">#include <stdio.h> int main() { int x = 10; printf("x 的符号为: %d\n", sign(x, int)); float y = -3.14f; printf("y 的符号为: %d\n", sign(y, float)); return 0; }</code>
Output:
<code>x 的符号为: 1 y 的符号为: -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!