About the inconsistency of parameter types in function declaration and invocation

Source: Internet
Author: User

Or the last one, because the old-style C function declaration can not specify the number and type of arguments, so the compiler does not check the function call.

Take a look at the following example:

#include <stdio.h>

int main (void)
{
	void foo ();
	void foo (double);
	char C =;
	Foo (c);
	return 0;
}

void Foo (double D)
{
	printf ("%f\n", d);
}
You'll notice that the program runs 0.000000.

The debug run will find that:

1. Because the Foo function is declared void foo (void), the argument C is not passed in at all;

2. Local variable D is a random value, my machine is 2.5463949521227207e-313, this number has exceeded the range represented by double so print out 0.000000


If you replace the declaration statement with a comment, you will find that the program runs 60.000000

Declaration and implementation are consistent, parameters can be passed, although calling Shishun is a char value, but the runtime enforces the type conversion to double.




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.