© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

12. Are pointers integers?

Ans:

No, pointers are not integers. A pointer is an address. It is merely a positive number and not an integer.

Ex - 1:  Is the following code legal?
struct a
    {
int x;
            struct a *b;
    }

Ans:
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. 

Ex - 2 Is the following code legal?
typedef struct a
    {
int x;
 aType *b;
    }aType

Ans:
No

Explanation:

The typename aType is not known at the point of declaring the structure (forward references are not made for typedefs).


SLogix Student Projects
bottom