What is function prototype in C language

CServer Side ProgrammingProgramming

A function is a self-contained block that carries out a specific well-defined task.

Types of functions

Functions are broadly classified into two types which are as follows −

  • Predefined functions
  • User defined functions

Communications among functions

Functions communicate among themselves by using arguments and return value.

Farm of ‘C’ function for return-datatype function name (argument list) is as follows −

{
   local variable declarations;
   executable statements(s);
   return (expression);
}

For Example, void mul (int x, int y).

{
   int p;
   p=x*y;
   printf(“product = %d”,p);
}

Prototype functions

These functions can be done in two ways as explained below −

  • Create a copy of the function declaration with the arguments typed, with or without identifiers for each.

For example,

int func(int, float, unsigned [2]);
int func(int i, float f, unsigned u[2]);
  • We can also prototype a function by writing the function definition in prototype form.

For example,

int func(int i, float f, unsigned u[2]){
   < code for func >
}

Use of function prototype

  • A prototyped function which is called with one or more arguments of incompatible type.

  • When the explicit or implicit declarations for the same function are encountered. This version of the compiler scrutinizes the duplicate declarations carefully and catches inconsistencies.

raja
Published on 31-Aug-2021 13:05:37
Advertisements