0
Can anybody please answer . Why we use function prototype and parameters and give explaination please..
C program
2 Answers
+ 3
The compiler do its job from the top to the bottom of the code.
The prototype gives the compiler a way to check if you are using your function in the proper way.
Let's say that you do not write any prototype before the main. Now if you declare a function (after the main) that recieves an int as argument, but in the main you used this function giving it a char value, then the compiler wouldn't tell you anything, and yet your program would not function properly.
So even though prototypes are not required for the program to work, you use them for your own sake, to know if you have done mistakes.
If you use the prototype, it needs to be coherent with the declaration in number, type and order of arguments and in returned type. Otherwise the compiler will give you errors, that is exactly what you want.
edit: In case you don't give a prototype, the compiler uses a default one and warns you about the missing prototype (and eventually about a mismatch between your function declaration and the default prototype)
0
NotAPythonNinja can u explain a program using parameters