EASY ONE!!!!

1 view
Skip to first unread message

shona

unread,
Aug 12, 2010, 9:37:22 AM8/12/10
to Knowledge Test
int (*fptr) (int, int);

here fptr is function pointer...
How compiler knows that it is a function pointer ????
as all pointers are of 4 bytes only...

TheSuyog

unread,
Aug 12, 2010, 11:01:48 AM8/12/10
to Knowledge Test
Function pointer or not, a pointer is always an ordinary pointer. Its
type depends on not the size (as its same in both cases) but 2 facts
that (1). its got arguments in its declaration which it passes to the
function it points to, like ur example states int (*fptr) (int, int);
and if the function pointer points to function with no arguments then
simply int (*fptr) (void); and (2). it points to a location where a
function starts. The 2nd fact comes into handy at runtime, at compile
time compiler distinguishes between a function pointer and an ordinary
pointer through the 1st fact.

I hope I'm clear.
Reply all
Reply to author
Forward
0 new messages