Binding What is binding? Solution. What is static binding? Give a piece of code
ID: 3816654 • Letter: B
Question
Binding What is binding? Solution. What is static binding? Give a piece of code as an example. What is dynamic binding? Give a piece of code as an example. Multiple Choice. Select the best choice. _____ are generally bound at load time. a. Global variables b. Predefined identifiers c. All variables d All attributes The scope of a binding is _____. a. the region over which the binding is maintained b. the precision of the binding c. the time when the binding takes place d. the magnitude of the bindingExplanation / Answer
Binding refer to the process for converting functions and variables into machine language address. There are in general two types of binding static binding and dynamic binding.
Static binding
Also known as early binding:
Static binding is binding for which compiler has already resolved ambiguity at compile time and there will be no ambiguity at run time. Example method overloading in a say class hirerchy.
class foo
{
void display();
}
class bar : public foo
{
void display();
}
bar b;
b.display() // will call b's display and is known at compile time
Dynamic binding
It is also known as run time binding. Dynamic binding get resolved at run time only based on what is being done. It is impossible to determine behaviour at compile time as it depend on what objecta nd how they are created and used.
For example calling methods using function pointer.
void display(string meesage);
void dance(string moves);
void (*funcptr)(string);
if(input == 1)
pt = display;
else
pt = dance;
pt(inputString)
3
1)
All variables are bounded ar load time.
2)
The region over which the binding is maintained.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.