Question

In: Computer Science

What is the binding time for the following in C/C++ program. Explain. a. The location of...

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

Solutions

Expert Solution

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 time
Any 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.


Related Solutions

The following table gives temperature data in *C as a function of time of day and day of the week at a specific location.
The following table gives temperature data in *C as a function of time of day and day of the week at a specific location. Data are missing for the entries marked with a question mark (?). Use linear interpolation with MATLAB to estimate the temperature at the missing points.
Location A Location B Location C Location D 52                   75                &nb
Location A Location B Location C Location D 52                   75                  67                  58 59                   55                  77                  38 81                   95                  47                  82 63                   46                  74                  77 73                   85                  56                  91 Test the following hypotheses and also state the alternate hypothesis in each case. Write a sentence or two summarizing your conclusion after you have completed each hypothesis testing. Hypothesis 1 The average time spent per table in Location A is the same as the average time spent per table in Location B....
Write a C program in Unix which uses a function called search to find the location...
Write a C program in Unix which uses a function called search to find the location of a value in THREE arrays of floats. The function should take three parameters :          the value to be found          the array to be searched          the size of the array N.B.!!!! The main program should read in three arrays of varying size          example : array a has twelve elements                    array b has six elements                    array c has nine...
explain the distinction between binding site and binding region
explain the distinction between binding site and binding region
What are some of the conditions of a binding Contract? Please explain
What are some of the conditions of a binding Contract? Please explain
What features of the binding site hinder oxygen binding to Hb? What feature of the binding...
What features of the binding site hinder oxygen binding to Hb? What feature of the binding site facilitates oxygen binding to Hb? Explain the Bohr effect using the theory of allosteric modulation of oxygen binding to hemoglobin.
Can anyone clearly explain: 1. What is end-stacking binding mode in Triplex DNA binding? 2. How...
Can anyone clearly explain: 1. What is end-stacking binding mode in Triplex DNA binding? 2. How are the effects of the end-stacking when a ligand binds with a triplex DNA? 3. How is binding affinity involved in this case?
Write a C++ program to calculate the time to drain a cylindrical water tank for an...
Write a C++ program to calculate the time to drain a cylindrical water tank for an initial water height ranging from 1 to 10 feet (specifically for 1, 2, 4, 6, 8, and 10 ft). The tank has a radius (rt) of 2 feet and the drain radius (rd) is 0.3 inch. The gravitational constant (g) is 32.2 feet/sec2. The formula for time to drain the tank is time=(rtrd)2h/vavg where, average velocity, vavg=0.5(2gh).5 In your program, assign the values to...
Use any C program without using PTHREADS calculate time taken to execute program. Write same program...
Use any C program without using PTHREADS calculate time taken to execute program. Write same program of question 1 using PTHREADS. Calculate time taken to execute program.(1 mark) Identify data races in above program and explain why this situation occurred with an example (1 mark) Rewrite the code to avoid data races should use any of the THREE techniques.(1.5 marks) please I need the c code.. critical section mutex solution semaphore functions Barriers Read-Write Locks Run program using 1, 2,...
2. Run the following C program, and submit the screenshot of the result. Also briefly explain...
2. Run the following C program, and submit the screenshot of the result. Also briefly explain the result. #include <sys/types.h> #include <stdio.h> #include <unistd.h> #define SIZE 5 int nums[SIZE] = {0,1,2,3,4}; int main() { int i; pid_t pid; pid = fork(); if (pid == 0) { for (i = 0; i < SIZE; i++) { nums[i] *= -i; printf("CHILD: %d ",nums[i]); /* LINE X */ } } else if (pid > 0) { wait(NULL); for (i = 0; i <...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT