Why does this C program compile?

Posted by AdmiralJonB on Stack Overflow See other posts from Stack Overflow or by AdmiralJonB
Published on 2012-12-19T10:48:39Z Indexed on 2012/12/19 11:03 UTC
Read the original article Hit count: 158

Filed under:
|
|

I've just come across someone's C code that I'm confused as to why it is compiling. There are two points I don't understand.

First, the function prototype has no parameters compared to the actual function definition. Secondly, the parameter in the function definition doesn't have an type.

#include <stdio.h>

int func();

int func(param)
{
    return param;
}

int main()
{
    int bla = func(10);    
    printf("%d",bla);
}

Could someone please explain to me why this works? I've tested it in a couple of compilers and it works fine.

© Stack Overflow or respective owner

Related posts about c

    Related posts about parameters