Question 1th: The worthwhile conversion of signed and unsigned variables

Source: Internet
Author: User

#include  <stdio.h>char getchar (int x,int y) {         char c;        unsigned int a = x ;         (a + y > 10)  ?  (c =  1)  :  (c = 2);         return c;} Int main (void) {        char c1 = getchar (7,4);         char c2 = getchar (7,3);         char c3 = getchar (7,-7);         char c4 = getchar (7,-8);        //c1 =  1        printf ("c1 = %d\n", &NBSP;C1);         //c2  = 2        printf ("c2 = %d\n", &NBSP;C2);         /*c3 = 2  unsigned types and signed types for operation,         *  signed types are implicitly converted to unsigned types         * - 7 converted unsigned value plus 7 just above overflow, the result is 0        */         printf ("c3 = %d\n",  c3);         /* c4  = 1        * -8 converted unsigned value plus 7 becomes a very large integer (the difference of 1 will overflow)          */        printf ("c4 =  %d\n ",  c4);         return 0;}


This article is from the "Walt" blog, make sure to keep this source http://water3700348.blog.51cto.com/13058625/1965238

Question 1th: The worthwhile conversion of signed and unsigned variables

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.