0

i recently saw the following code in C which is said to be valid but I'm not sure.

    int max(x,y)
    int x,y;
    {
    return (x>y)?x:y;
    }

Is this kind of function prototype valid? If so please give some reference to learn more about that.

Abhilash
  • 2,026
  • 17
  • 21
  • [See this also](http://stackoverflow.com/questions/1630631/alternate-c-syntax-for-function-declaration-use-cases). This question has been asked many times before. – Lundin Mar 08 '16 at 14:55

2 Answers2

5

This is the old-style "K&R" way of defining functions. The new way is better, so don't write code like this yourself.

Thomas Padron-McCarthy
  • 27,232
  • 8
  • 51
  • 75
2

This code is valid, it's just a pretty old standard.

Nowadays in function declaration the types of arguments are declared right before the names of these arguments:

int main(int argc, char **argv)

But years ago there was another standard where the syntax was different: you had to specify the types like this:

int main(argc, argv)
    int argc; char **argv;

So, nothing weird here, different standards offer different syntax

Thomas Padron-McCarthy
  • 27,232
  • 8
  • 51
  • 75
ForceBru
  • 43,482
  • 10
  • 63
  • 98