In: Computer Science
What is the binding time for the following in C/C++ program. Explain.
a. The location of memory of a local variable in a function.
b. The meaning of the keyword while
c. The size in memory of a variable of type int
d. The location in memory of a global static variable
e. The code for the printf function
f. The type of local variable in a function
g. The values assigned to a variable
h. The size in memory of a pointer
Binding is association of two or more attributes with names at a particular time .
Binding is done for each variable and functions.
In general, biding is done at
Static time: Variables, attributes, name are resolves at compile-time.
Dynamic time: Variables, attributes, name are resolves at run time.
a. The location in memory of a local variable in a
method.
Dynamic Binding or Run time
When the method is invoked, a run time stack is created for called
method which has activation record.
An activation record contains return address of calling method,
parameters, local variables.
So local variables of a method have space allocated, when method is
invoked at run time.
b. The meaning of the keyword while.
Language definition time- Static binding or Compile
time.
c. The size in memory of a variable of type int
Language implementation time - Static binding or Compile
time.The compiler will need to know the size of integer to
compute required memory. So the compiler computes this at compile
time.
d. The location in memory of a global static
variable.
Static Binding or Compile timeAny variable declared with
global scope, static or extern variable will occupy memory at
compile time.
e. The code for the printf function
Static Binding or Compile time
printf() function belongs to stdio.h, which is static
library
For a static library, the actual code is extracted from the library
by the linker and used to build the final executable at compile
time. Library code is connected at compile time and hence code for
printf function is also doing static binding.
f. The type of local variable in a function
Static binding or Compile time
Type checking is done by compiler only.
g. The values assigned to a variable
Dynamic binding or Run time.Except constant variable,
values of a variable are resolved at run time.
h. The size in memory of a pointer
Language implementation time.
The compiler will need to know the size of integer to compute
required memory. So the compiler computes this at compile
time.