7th Day of Learning C

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.