#include <stdio.h>
int main ()
{
int x=0;
if (x==0)
{
printf ("x is false \ n");
}
Else
{
printf ("x is true \ n");
}
return 0;
}
if (x==0) can also be written as if (!x), because The value of x is 0 is false, so !x is true, The computer can only recognize the values of 0 and 1 , which is difficult to understand, not recommended, good programmers write code is easy to understand
#include <stdio.h>
int main ()
{
int x, y;
printf (" Enter an integer:");
scanf ("%d", &x);
Y= (x<0)-x:x;
printf (" the absolute value of this number is:%d\n", y);
return 0;
}
Y= (x<0)-x:x; the right side of the expression is a conditional expression with three operands, respectively. And: separated, so? : This is called the trinocular operator, and when the x<0 is true, the value of - x is taken ( Absolute ), Take The value of x when it is false
#include <stdio.h>
int main ()
{
int x=1,y=2,z;
z=x>y?x:x>y?x:y;
printf ("z:%d\n", z);
return 0;
}
The order of the Trinocular operators is executed from right to left
#include <stdio.h>
int main ()
{
int a=1,b=2;
printf ("%d\n", (a>b) a:b);
return 0;
}
The above is a flexible application of a three-mesh operator
#include <stdio.h>
int main ()
{
int a=1;
float b=2.1f;
printf ("%f\n", a>b?a:b);
return 0;
}
The trinocular operator can manipulate not only integers, but also floating-point numbers
#include <stdio.h>
int main ()
{
Char A;
scanf ("%c", &a);
printf ("%c\n", a= (a>= ' a ' &&a<= ' Z ')? ( A+32): a);
return 0;
}
(a>= ' A ' &&a<= ' Z ') Judging a whether the value of this variable is in uppercase A- z between, (a+32) means to convert lowercase into larger
7th Day of Learning C