[SOLVED] CSE505 Assignment 2–Higher-order Procedures 

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Assignment-2-wq1vix.zip (444 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
Rate this product

 

  1. This question is about static scoping, recursion, and higher-order procedures in the C programming language. Run the following C program through Gnu C compiler:

#include <stdio.h>

int main() {        int x, y;

void p1(int y, void q(int)) {                void p2(int x) {                      x = y + 2;                         printf(“%d\n”, x);                      q(y);

}

if (x == y)

q(y);                       else p1(y+1, p2);

}

void p2(int x) {             x = y + 2;            printf(“%d\n”, x);

}

x = 2;    y = 2;        p1(0, p2);

}

  1. What is the sequence of values printed?
  2. Draw a Scope Diagram at the point when the last value was just printed.
  3. Draw a Stack Diagram at the point when the last value was just printed.

Prepare your answers to parts a, b, and  c in a file A2_problem1.pdf.  Refer to Lecture 10 for Scope and Stack Diagrams as well as closures.   Please note:

  1. In the Scope Diagram, for every call on p1, be sure to show the “closure” that is passed to q in addition to the value bound to y. It is important to correctly nest the frames for procedure calls.
  2. In the Stack Diagram, it suffices to show just the names of the stack frames along with the

static and dynamic links.  Internal details of procedures p1 and p2 are not required.

Compiling and running a C program (say, program.c) using the Gnu C compiler under Linux:

  1. Compiling c: /util/bin/gcc  program.c
  2. Executing c: ./a.out

 

 

  • Assignment-2-wq1vix.zip