Forward Declaration and Forward reference and Function Prototype

Forward Declaration:

Declaring the function prototype before it is defined is known as forward declaration for function and declaring the variable before using it is forward declaration for variables.

The purpose is to save compilation time as it causes the storage space set aside so that values can be set later.

Function prototype:

It tells the compiler to expect the function in a given way that is it tells the compiler the name of the function, return type, number of parameters and sequence of parameters.

Forward Reference:

It is use of function before it is defined.

#include <stdio.h>
int add(int, int);   ==> Function prototype or forward declaration
int main()
{
  if (add(4,5) ==9) ==> Forward Reference, using before it is defined
   printf("\n The result is 9");
   return 0;
}
/* Function definition */
int add(int a, int b)
{
  return (a+b);
}
Output:
The result is 9


Categories: C Language

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: