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

質問

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"

役に立ちましたか?

解決

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;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top