Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this weird function definition mean?

Tags:

c

function

I came across this C program in a blog post:

main()
{
    int n;
    n = 151;
    f(n);
}

f(x)
int x;
{
    printf("%d.\n", x);
}

The post doesn't explain it. Can anybody explain what this weird function definition means?

like image 828
opu 웃 Avatar asked Mar 21 '14 06:03

opu 웃


Video Answer


1 Answers

This is the K&R style of C code, it's still valid C syntax, but I suggest you not using it in new-written code.

f(x)
int x;

is equivalent to ANSI C:

void f(int x)

K&R C is the C language described in the first edition of the book C programming language by Brian Kernighan and Dennis Ritchie, and named after the two authors. The second edition of the book updated to use ANSI C.

like image 109
Yu Hao Avatar answered Oct 07 '22 21:10

Yu Hao