Automatic conversion of parameter symbols during C language operations

Source: Internet
Author: User

A simple question? In C, which of the int and unsigned int have a large value range? Note that the value 0 contains + 0 and-0 in the int, and the value 0 in the unsigned int has only one + 0, so the value range of the unsigned int is greater than that of the int. The C language operation code is as follows: # include <stdio. h> int main (int argc, char ** argv) {int val =-15; unsigned int value = 13; int sum = value + val; printf ("sum % d \ n", sum); return 0;} What is the sum result above? Think for the answer to this question. In the C language formula, if there are different types of variables, variables with a small value range will be automatically converted to the type of variables with a large value range. Therefore, the C language conversion rules are: variables such as www.2cto.com 1 char and short will be automatically upgraded to int type variables 2 unsigned char and unsigned short variables will be automatically upgraded to unsigned int type variables 3 There are unsigned and signed type variables, the type of a variable with a small value range will be upgraded to the type of a variable with a large value range. According to the third rule above, the val operation type in the above Code is unsigned int. Many other so-called rules can be easily deduced using the third rule.

Related Article

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.