function declaration or prototype in C programming Language.

  Functional Declaration / Prototype in C Language.
Let understand function declaration or prototype from the Given Diagram .
The diagram given has the syntax for function declaration or prototype.
and
The function pototype example to find the area of circle.
Function declaration allows other parts of the program to use the function without knowing its implementation details.
Function declarations are speacialy placed in (.h) header files and are included in other (.c)files using the directive such as #include .
A programmer or user had to declare the function before using in a program.
Without function prototype or declaration function implementation or definition can not work out in the program. it is one of the syntax or rule for declarations of function in c programming language.

The general syntax for function Declaration.

Syntax:
return-type function-name(param1,param2,....);

Let us understand the given syntax in detail:
The syntax given for function declaration consist the returntype ,functionname and parameter list.
return type: after successful execution every function in c return a value .
The return-type specifies the kind or type of value that the function will return after complete execution. return type should be a valid data type used in C programming, such as int, char, float, void, etc. The return type of the function should be void If the function does not return a value.
function-name:The function-name is used to call and identify the function in the program. The function-name should have unique within the scope or life time of the program.
The name of the function should be descriptive while used in the program.
Parameters:Parameters are optional and are used to pass values to the function. They act as placeholders for the values that will be provided when the function is called. Multiple parameters can be separated by commas.
parameter have argument-type and argument-name.
Argument type is the valid c data type and argument name is the name of the function.
float areaCircle (float r);
is the function declaration/prototype to find the area of circle.

Function Declaration/Prototype example

C program to find the area of circle
/* C Program to find area of circle and illustrate function declaration/prototype*/
#include <stdio.h>
float areaCircle(float r);  // Function declaration or prototype
int main()
{
 float r,Area=0.0;
 printf("Enter the radius of a circle: ");
 scanf("%f", &r);
 Area = areaCircle(r); // Function call
 printf("The area of the circle is=: %.2f\n", Area);
 return 0;
}
float areaCircle(float r) // Function definition
{
  return 3.14*r*r;
}
Ouput:
Enter the radius of a circle:
5
The area of circle is =78.50

Program Explanation:
In the given above program example, the header file have been included for input/output operations. Then, we have declare the function areaCircle() which one is used to find the area of circle. In The main function printf() function prompts the user to "enter the radius of the circle". scanf() function reads and store the input radius 5 in variable r, and then calls the areaCircle() function with the provided radius. Finally, the calculated area i.e 78.50 is printed to the console.


Previous Topic:-->> Function Definition in C || Next topic:-->>Types of Function in C.