top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Is forward reference and declaration in C are same?

+3 votes
680 views
Is forward reference and declaration in C are same?
posted Jun 17, 2014 by Sanjeet Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Both are different see the following explanation

Forward Declaration
Declaration of a variable or function which are not defined yet and their definition will appear later called forward declaration. It saves compilation time.

Example

int myfunc(int x); // forward declaration of myfunc
...
...
int myfunc(int x) {
   return true;
}

Forward Reference
A forward reference means use of function or variable before its declaration which is opposite of the Forward Declaration. For example:

Example

int first(int x) {
   if (x 000) return 1;
   return second(x-1); // forward reference to second
}

int second(int x) {
   if (x == 0) return 0;
   return first(x-1);
}

But in general I agree with your intention of the query as these two are used as a synonym of each other.

answer Jun 17, 2014 by Tapesh Kulkarni
Similar Questions
...