C--The printf function parameter type and print format do not match

Source: Internet
Author: User
Tags print format

In C, a variable has an automatic conversion of the type when it is evaluated or assigned. The general situation is no longer discussed here, just say the assignment and use the printf function when printing the situation

1. Automatic conversion when assigning a value

int a = 1.5;

printf ("%d", a);

The output value is 1 because 1.5 is a double type, but when assigned to a, because a is an int type, the fractional part is put out, A is 1

Automatic conversion not involved in 2.printf functions

He only prints in a fixed format, and if parsing fails, it outputs 0 of the corresponding format

For example:

int a = 1;

printf ("%f", a);

Output 0.000000 because A is of type int, parsing fails with the float type, so 0 of the output floating-point format is 0.000000

  

The rest of the similar, such as%c fails to parse the output of a space,

C--The printf function parameter type and print format do not match

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.