Question

1) Given the following ‘generic’ program. var aVar; aVar = 10; sub1(); function sub1 () {  &...

1) Given the following ‘generic’ program.

var aVar;

aVar = 10;

sub1();

function sub1 ()

{

    Sub2();

    Print (“ aVar = “ aVar + “\n”);

}

function sub2()

{

   var aVar;

   aVar = 4;

}

What would be output under static-scoping rules?

What would be output under dynamic-scoping rules?

2)

Discuss and compare the following memory allocation strategies for variables, give an example of how Java and/or Python uses each:

  1. Stack-Dynamic
  2. Explicit Heap-Dynamic
  3. Implicit Heap-Dynamic

3) What is a descriptor? What are the required entries in a Java array descriptor for an int and when must they be stored (compile-time or run-time)? Compare this to a Python descriptor for an int.

4) Identify and explain the two common problems with C++ pointers?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

to the toP Icvel viYonhyn man10 when we wil e Print Stakmn able rekrsto the most recent environment-一nina He 2Briets sPeak n

3. java.io.FileDescriptor works for opening a file having a specific name. If there is any content present in that file it will first erase all that content and put “Beginning of Process” as the first line. Instances of the file descriptor class serve as an opaque handle to the underlying machine-specific structure representing an open file, an open socket, or another source or sink of bytes.

  • The main practical use for a file descriptor is to create a FileInputStream or FileOutputStream to contain it.
  • Applications should not create their own file descriptors.

4.

  • Dynamically allocated block needs to be freed explicitly. Otherwise, it would lead to memory leak.
  • Uninitialized pointers might cause segmentation fault.
  • Arrays passed as a function parameter decay to a pointer to the first element of the array, obscuring whether the parameter is intended to point to an array or a single data element.
Add a comment
Know the answer?
Add Answer to:
1) Given the following ‘generic’ program. var aVar; aVar = 10; sub1(); function sub1 () {  &...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following JavaScript skeletal program: //the main program var x: function sub1 () { var...

    Consider the following JavaScript skeletal program: //the main program var x: function sub1 () { var x: function sub2 () { } } function sub3 () { } Assume the execution of this program is in the following unit order: main calls sub1 sub1 calls sub2 sub2 calls sub3 a. Assuming static scoping, which declaration of x is the correct one for a reference to x in: i. sub1 ii. sub2 iii. sub3 b. Repeat part a, but assume dynamic...

  • Consider the following program, written in JavaScript-like syntax: // main program var x, y, z; function...

    Consider the following program, written in JavaScript-like syntax: // main program var x, y, z; function sub1() { var a, y, z; . . . } function sub2() { var a, b, z; . . . } function sub3() { var a, x, w; . . . } Given the following calling sequences and assuming that dynamic scoping is used, what variables are visible during execution of the last subprogram activated? Include with each visible variable the name of the...

  • Given the following Ada program: procedure Main is X, Y: Integer; procedure Sub1 is Y, Z:...

    Given the following Ada program: procedure Main is X, Y: Integer; procedure Sub1 is Y, Z: Integer; begin -- of Sub1 point 1 Sub2; end; -- of Sub1 procedure Sub2 is X: Integer; procedure sub3 (B: Integer) is W: Integer; begin -- of Sub3 point 2 end; -- of Sub3 begin -- of Sub2 point 3 Sub3 (X); end; -- of Sub2 begin -- of Main point 4 Sub1; end; -- of Main For each of the four marked points,...

  • 1. Which of the following is a problem with dynamic scoping? Readability Access to nonlocal variables...

    1. Which of the following is a problem with dynamic scoping? Readability Access to nonlocal variables takes longer Static type checking may not be possible 2.Languages with dynamic type binding are usually implemented using: Compilers Interpreters Hybrid implementations JIT 3.Which variables are created using operator new? Static Stack-dynamic Explicit heap-dynamic Implicit heap-dynamic 4.Which variables are bound to memory cells before program execution and remain bound to the same memory cell during program execution? Static Stack-dynamic Explicit heap-dynamic Implicit heap-dynamic

  • a. What is the referencing environment at location 1 in the program below? Use static scope...

    a. What is the referencing environment at location 1 in the program below? Use static scope rules. Include what functions the variables are declared in. void g ( int w) { var b = 1; var x = 8;         void f()         { varb = 3;                       x = b + 1; print “f: x = “ , x ;                        ….             < - - - - - - - - - - //Used in Prob a //location 1...

  • 8. (10%) Consider the following JavaScript program: // The main program var x,y; function f10{ var...

    8. (10%) Consider the following JavaScript program: // The main program var x,y; function f10{ var y, z; function f20{ var x, Z, P; function f30{ var x, z, ; Assume that the execution of this program is in the following unit order: main calls f3, f3 calls f1, f1 calls 12. a) Assuming that static scoping is in effect, indicate which version of each of the following variables will be visible in f2 by filling in each blank with...

  • Consider the following JavaScript-like program: 1 function subl) 2 var x 4 function sub2) // crea...

    Consider the following JavaScript-like program: 1 function subl) 2 var x 4 function sub2) // creates a popup box alert (x) 9 function sub3) 10 var x x3 sub4 (sub2); 12 13 14 15 function sub4 (subx) 16 17 18 19 20 21 22 ub30 23 24 subl 0; var x subx ) Give the output of this program when executed using a. (2p) deep binding Solution b. (2p) shallow binding Solution C. (2p) ad-hoc binding Solution Consider the following...

  • NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! MULTIPLE CHOICE no explanation...

    NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! MULTIPLE CHOICE no explanation needed SPRING Cs 424-524 aUESTION 1 12 points each, 30 points total +2 extra) Multiple 1. The main reason to include enumeration types in a programming language is to TEST2 choice: circle or check the best answer a. Make programs run faster b. Improve program readability c. Eliminate unnecessary /O d. Reduce type errors 2. A C++ value parameter is an example of a....

  • 17. Given the following definition of function £, what does the expression "t (1: 2: 3]::" return? let rec f listl match listl with 1 I head::rest -> head f resti b. 6 c. 120 d. 123 456...

    17. Given the following definition of function £, what does the expression "t (1: 2: 3]::" return? let rec f listl match listl with 1 I head::rest -> head f resti b. 6 c. 120 d. 123 456 e. g. 14; 5; 6] h. (6; 5; 4] i. Error message j. None of the above 18. Which of the following is the correct meaning of the C declaration "double (*a [n]) "? a is an array of n pointers to...

  • 10 L 1 22 Given the function below, that divides the original array in two arrays...

    10 L 1 22 Given the function below, that divides the original array in two arrays of half size, develop the Java code that combines two sorted arrays or clearly explain how to implement the merge function. (3 points) nt middle values.Length/2; // divide array into two arrays of half size nt left- new int[middle]; or Cint i-e; imiddle; i+) t Leftri] - values[iJ: ntD right- new int[values. length-middle]: or Cint i-a; i<values.length-middle; i++) t rightli] -values [middle+i]; ort(left); //recursively...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT