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?
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?
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.
f(x)
int x;
{
printf("%d.\n", x);
}
is an older way of defining function. Now it can be read as
void f(int x)
{
printf("%d.\n", x);
}
This code is simply bad.
f()
f()
before main()
f()
please change your c learning source!
that is a very old style of C (K&R C).
f(x)
int x;
{}
is equivalent to
void f(int x)
{}
you should really not wasting time learning that.
look for sources that teach ANSI C C89/C90 and also note the new features of C99 (that isn't widely adopted by many compilers, so know the differences)
This is a very old style of coding. This doesn't work out in ANSI. Better use something like
void f(int x)
{
... ... ...;/*Whatever is required*/
}