C Language

Function Prototype

In C Language by Baqir Ali1 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.

Get The Coding Examples From C Language Code Example Page

Comments

  1. Pingback: Function in C - Learn to code like a pro

Leave a Comment