Monday 1 April 2013

Is the following code legal? (2)


 Is the following code legal?
struct a
    {
int x;
            struct a *b;
    }
Answer:
Yes.
Explanation:
*b is a pointer to type struct a and so is legal. The compiler knows, the size of the pointer to a structure even before the size of the structure
is determined(as you know the pointer to any type is of same size). This type of structures is known as ‘self-referencing’ structure.

Blog Author: Vijay Kumar

No comments:

Post a Comment