In this tutorial section we will learn function Declaration/prototype in C Language.
Function Declaration:a function declaration is a statement in C program that tells the compiler about the the function without providing its implementation details. function declaration specifies the function's name, return type, and the list of parameters.
Most of the time function dclarations are placed in to the header files (.h) and are useful to make the function known to other parts of the program.
the function declaration at its core is a way to define a function in C programming.
Function declaration is very essential in C programming , it allows programmer to define blocks of code and reuse it easily whenever needed.
declaring a function before its usage, the compiler perform necessary checks such as verifying the function name number and types of arguments passed to the function and return type of the funcion. This helps in ensuring proper function invocation and detecting errors .
Functional Declaration / Prototype in C 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
Previous Topic:-->> Function Definition in C || Next topic:-->>Types of Function in C.
Other Topics:
Variables and Identifiers
Relational Operators
if-else statements
Switch case
While Loop
Infinite while Loops
C FOR Loop
Infinite for Loops
Continue in Loops
One Dimensional Array
Two Dimensional Arrays
Read and Display 2D Arrays
Types of functions
Passing Array To Functions
Nesting of Function
Array vs Structure
Array of Structure
Structures and Functions
Structures Within Structures
Use Of Pointers In C
File Handling In C
Loops FAQ
Arrays FAQ
count vowels in a file
Function FAQ
Conditional Statements Assignments
For Loops Assignments
Arrays Assignments
Function Assignments
Structure Assignments
Pointers Assignments
Files Assignments
Storage classes Assignments
Binary Files
count words,lines in a file
Copy files
Update File
Continue in Loops
break in Loops
Difference Between While and Do while
difference while do..while & for
malloc
calloc
Storage Classes
Operators MCQ
Conditional Statements MCQ
Loops MCQ
Arrays MCQ
Function MCQ
Structure MCQ
Pointers MCQ
Files MCQ
Storage classes MCQ