The compiler reads a file from top to bottom. If it meets a call to a function it has not seen yet, it cannot check the call. A prototype introduces the function in advance. This section explains declarations, prototypes and the checks they make possible.
Declaration versus definition
Declaration (prototype)
Definition
Contains
Return type, name, parameter types, then a semicolon
Header plus the body in braces
Purpose
Tells the compiler the function exists and how to call it
Provides the actual code
How many
May appear several times
Exactly once in the program
Example
int square(int no);
int square(int no) { return no * no; }
Parameter names are optional in a prototype: int square(int); and int square(int no); are equivalent, but names make the prototype easier to understand. A function that takes no arguments is declared with void: int cal_sum(void);.
What the compiler checks
With the prototype visible, the compiler verifies each call:
the number of arguments,
the types of the arguments (converting where C allows it, such as int to float),
the use of the return value.
Without any declaration, a call is an error in modern C.
Where prototypes go
The usual place is near the top of the file, after the #include lines and before main. Every function below can then call the function. The header files you include, such as <stdio.h>, are collections of prototypes for library functions.
Key takeaways
A declaration (prototype) introduces a function; a definition supplies its body.
The prototype must appear before the first call, usually at the top of the file.
The compiler uses it to check the number and types of arguments.
Parameter names are optional in prototypes.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Explain the difference between a function declaration and a function definition, using int max(int a, int b) as the example.
Show worked answer
The declaration is int max(int a, int b);. It ends with a semicolon, has no body, and only tells the compiler that a function named max takes two int values and returns an int, so calls can be checked. The definition is int max(int a, int b) { return (a > b) ? a : b; }. It repeats the header and adds the body, which is the code that actually runs. A function may be declared many times but must be defined exactly once.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/functions/function-declarations-and-prototypes/ to read this page.