# Thread: function prototype logical explanation?

1. ## function prototype logical explanation?

In lesson 4 the function protoype is written like this:
Code:
```int mult ( int x, int y );
...```
I do not understand it why int x and int y is in there, I've rewritten the entire function prototype like so:
Code:
```int func_1(int,int);
...```
and it still works exactly as expected? (removing "int,int" breaks it)
And logical explanation behind this?

2. The compiler needs to know the function's parameter types (more specifically, the types' sizes). Naming of parameters is necessary if you need to refer to them in the function body, naturally.

The compiler needs to know the function's parameter types (more specifically, the types' sizes). Naming of parameters is necessary if you need to refer to them in the function body, naturally.
I can understand why removing "int,int" breaks it but the int "x, int y" thingy doesn't really make any sense to me if you can just type "int, int" with exact same results. Is it like a safer way to do?

4. Maybe not safer, but arguably more self-documenting:
Code:
```void set_dimensions(int, int); // (width, height)? (height, width)?
void set_dimensions(int width, int height); // no doubt```
Personally, I never felt the desire to omit them and always use matching parameter names in function prototype and definition.

5. Originally Posted by unknown000
I do not understand it why int x and int y is in there...
...
And logical explanation behind this?
There are three things connected with creating a function:

1) Function declaration / prototype
2) Function definition
3) Function call

The function prototype tells the compiler the data type that will be returned from the function, and the parameter list.

The parameter list tells the compiler:
1) The number of arguments that will be passed into the function
2) The order of the arguments that will be passed
3) The data type of each argument

Most programmers will usually define the function, possibly changing the formal parameters during it's creation. When finished, the programmer will just copy the first line of the function definition, placing that line at the top of the file or in a header file included by the program, and put a semicolon at the end of the declaration, leaving the parameter names in place. The compiler does not need or require the names at that point, but if the parameter names are well thought out, it does help to self document the function.

Hope this clarifies this for you.

6. Everyone thanks for explaining, I do understand it better now.