C++ Virtual Functions Question:
Download Questions PDF

Can you please explain the difference between static and dynamic binding of functions?

C++ Virtual Functions Interview Question
C++ Virtual Functions Interview Question

Answer:

Static Binding:
By default, matching of function call with the correct function definition happens at compile time. This is called static binding or early binding or compile-time binding. Static binding is achieved using function overloading and operator overloading. Even though there are two or more functions with same name, compiler uniquely identifies each function depending on the parameters passed to those functions.

Dynamic Binding:
C++ provides facility to specify that the compiler should match function calls with the correct definition at the run time; this is called dynamic binding or late binding or run-time binding. Dynamic binding is achieved using virtual functions. Base class pointer points to derived class object. And a function is declared virtual in base class, then the matching function is identified at run-time using virtual table entry.

Download C++ Virtual Functions Interview Questions And Answers PDF

Previous QuestionNext Question
What is general form of pure virtual function? Explain?Tell me what are static member functions?