Home > DeveloperSection > Forums > Default value of a function pointer in VC
Royce Roy
Royce Roy

Total Post:134

Points:938
Posted on    February-12-2013 3:11 AM

 Visual C++ Visual C++ 
Ratings:


 1 Reply(s)
 1575  View(s)
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



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    February-13-2013 12:38 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick