top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is a forward reference in c ?

+1 vote
412 views
What is a forward reference in c ?
posted May 31, 2014 by Kali Mishra

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

3 Answers

0 votes
 
Best answer

Using an identifier (variable) before its declaration results in an error. And to avoid this we just declare it but not define it and is called forward reference.

See the following example where it is necessary to define the forward reference as two structure are having cross reference -

struct foo; // Forward reference 

struct bar
{
   struct foo *f;
};

struct foo
{
   struct bar *b;
};
answer May 31, 2014 by Salil Agrawal
+1 vote

It is a reference to a variable or function before it is defined to the compiler. The cardinal rule of structured language is that everything must be defined before it can be used. There is rare occasions where this is not possible. It is possible to defined two functions in term of each other, Here one will obey the cardinal rule while other will need a forward declaration of the former in order to know of the former's existence.

answer May 31, 2014 by Amit Kumar Pandey
0 votes

given address of variable to others,

answer May 31, 2014 by anonymous
Similar Questions
+2 votes

I know about the forward declaration of structure but don't know when it should be used or preferrable ? I can't envision the scenario.

+3 votes

Called by reference is a mechanism where we can bring the changes to a variable done in the called function to calling function which can be done via passing pointers in C. But most of the books are referring that C does not support pass by reference method.

Can someone explain why?

...