In C, what does it mean when I declare a variable following a function signature, before the function body? [duplicate]

StackOverflow https://stackoverflow.com/questions/12765371

Question

Possible Duplicate:
Why are declarations put between func() and {}?

In C, what does it mean when I declare a variable following a function signature, before the function body?

Example:

int foo (i) int i {
    printf ("the value of variable 'i' is: %d", i);
    return i;
}

When I compile the the code in addition to initializing variable i, I get a compile error: "cannot initialize parameter: p"

Was it helpful?

Solution

It means you are looking at old code. That is the old K&R syntax.
Basically it says, i is the argument, and it is an int

You can rewrite it as

int foo (int i) 
{
    printf ("the value of variable 'i' is: %d", i);
    return i;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top