C Language

Function Prototype

In C Language by Baqir AliLeave a Comment

A function prototype is also called function declaration. It comes to use when the user defined function is defined after the main function in program then we use function prototype. such as

#include <stdio.h> 
int add(int a, int b);
void main (void)
    int x = 4, y = 20,  z;
    z =  add (x , y);
    printf ( “ %d \n ”,  z);
int add(int a, int b)
    int sum;
    sum = a + b;
    return sum;

function prototype consists of function definition signature line with a semicolon at the end defined before the main function after the preprocessor directives.

int add(int a, int b);

What is the purpose of using function prototype?

The function prototypes are used to tell the compiler about the number of arguments and about the required datatypes of a function parameter, it also tells about the return type of the function.

Leave a Comment