Search This Blog

Wednesday, August 12, 2020

Dynamic and Static Binding in C++

                               C++ Programming:-

In this tutorial you will learn:-


 Dynamic binding

 

Dynamic  memory is the process of linking procedure call to a selected sequence of code (method) at run-time. It means the code to be executed for a selected procedure call isn't known until run-time. Dynamic binding is additionally referred to as late binding or run-time binding.


Dynamic binding is an object oriented programming concept and it's related with polymorphism and inheritance.


Dynamic binding definition

Dynamic binding(dispatch) means a block of code executed with regard to a procedure(method) call is decided at run time.

Dynamic dispatch is usually used when multiple classes contain different implementations of an equivalent method. It provides a mechanism for choosing the function to be executed from various function alternatives at the run-time. In C++, virtual functions are wont to implement dynamic binding

 


Definitions of Static Binding

When compiler acknowledges all the knowledge required to call a function or all the values of the variables during compile time, it's called “static binding“. As all the specified information are known before runtime, it increases the program efficiency, and it also enhances the speed of execution of a program.


Static Binding makes a program very efficient, but it declines the program flexibility, as ‘values of the variable’ and ‘function calling’ are predefined within the program. Static Binding is implemented during a program at the time of coding.


Overloading a function or an operator are the instance of compile-time polymorphism, i.e. static Binding.


Difference between Static and Dynamic Binding


BASIS FOR COMPARISONSTATIC BINDINGDYNAMIC BINDING
Event OccurrenceEvents occur at compile time are "Static Binding".
Events occur at run time are "Dynamic Binding".
InformationAll information needed to call a function is known at compile time.All information need to call a function come to know at run time.
AdvantageEfficiency.Flexibility.
TimeFast execution.Slow execution.
Alternate nameEarly Binding.Late Binding.
ExampleOverloaded function call, overloaded operators.Virtual function in C++, overridden methods in java 

Mr. abhijeet dwivedi

Developer

Hey, I'm Abhijeet

0 comments:

Post a Comment

If you have any doubt, please let me know