Answer in brief
A declaration describes a function, a definition supplies its body, and a call executes it.
Declaration or prototype
int square(int number);
Meaning of the prototype
int before the name is the return type. square is the function name. int number specifies one integer parameter; the parameter name is optional in a prototype. The semicolon ends the declaration. A prototype does not contain the function body.
Definition
int square(int number)
{
return number * number;
}
Function call
In square(5), the value 5 is supplied as an argument. Control enters the definition, number receives 5 and the expression number * number produces 25. return sends the value back to the caller. The example declares the function before main and defines it afterwards.
Important rules
- Declare the function before its first call. Modern C does not provide an implicit function declaration.
- Keep declarations and the definition compatible, including the return type and parameter types.
- A prototype alone is not a definition; a used non-library function still needs a definition.
- In C11, write f(void) to declare no parameters. A declaration f() does not specify the parameter types.
Why prototypes are useful
The compiler can detect many wrong argument counts and incompatible types when a prototype is visible. A prototype does not prove the function computes the right answer; the body must still be tested. The sample square value is deliberately small enough for int arithmetic.
C program and output
/* CodeBhavya | PPS AR25 | Learning example */
#include <stdio.h>
int square(int number);
int main(void)
{
printf("Square = %d\n", square(5));
return 0;
}
int square(int number)
{
return number * number;
}
Sample input and output
This example uses values already written in the program.
Output
Square = 25
Related exam questions
Related questions in the function declarations category from the supplied papers. The marks below are the printed allocations, including any combined subquestion.
View this category in the exam question bank →