Function prototype and definition
Function Prototype:
A function prototype is also known as a function declaration.
A function declaration tells the compiler about a function name and how to call the function.
It defines the function before it is being used or called.
A function prototype needs to be written at the beginning of the program.
Syntax:
return-type function-name (arg-1, arg-2, ...);
Example:
void addition(int, int);
Function Definition:
A function definition defines the functions header and body.
A function header part should be identical to the function prototype.
- Function return type
- Function name
- List of parameters
A function body part defines function logic.
- Function statements
Syntax:
return-type function-name(arg-1, arg-2, ...);
{
//... function body
}
Example:
void addition(int x, int y)
{
printf("Addition is = %d",(x+y));
}
Drafted on 🌏 by,
Jal
☮
peace
Comments
Post a Comment