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

Frage

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"

War es hilfreich?

Lösung

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;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top