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

Total Post:149

Posted on    February-12-2013 3:11 AM

 Visual C++ Visual C++ 

 1 Reply(s)
 1868  View(s)
Rate this:


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


Total Post:604

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