DEFAULT VALUE OF A FUNCTION POINTER IN VC

Royce Roy

Total Post:149

Points:1043
Posted by  Royce Roy
 1904  View(s)
Ratings:
Rate this:

Hi!

What is the default value of a function pointer in VC++? (Apparently it can't be NULL, so what is it?)

How is this program supposed to behave and why?

struct S { void (*f)(); };

int Main()
{
    S s = S();
    s.f();   // What is the value of s.f?
}

Please Help me ASAP!

Thanks in advance

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Default value of a function pointer in VC

    Hi Royce!

    According your line of code, object s is zero-initialized which means the function pointer is NULL. 
    struct S { void (*f)(); }; 
    int Main() { S s = S(); 
    if ( s.f == NULL) std::cout << "s.f is NULL" << std::endl; } 

    Output: s.f is NULL

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!