激活记录长度

use*_*466 0 c activation-record

前三个问题分别得到6,4,3,但我不知道怎么弄清楚最后一个问题.但是,解决方案手册显示了7,5,4,18作为答案.

int sum(int x[], int N) {
  int k = 0;
  int s = 0;
  while (k < N) {
    s = s + x[k];
    k = k + 1;
  }
  return s; // the activation record for sum will be ____________ locations
}

int fred(int a, int b) {
  return a + b;  // (2) the activation record for fred will be ____________ locations
}

void barney(int x) {
  x = fred(x, x);//(2) the activation record for barney will be ____________ locations
}

void main(void) {
  int a[4];
  int x = sum(a, 4);
  barney(x); 
} // (3) the stack must have at least _____________ locations to run this program
Run Code Online (Sandbox Code Playgroud)

Sze*_*eri 5

我不知道你的书的惯例是什么,但我认为,总有一个地方可以找到返回地址,返回值的地址和中间结果

a)返回地址,返回结果的地址,x,N,k,s,s + x的中间结果[k] =总计7

B)沤.addr,ret结果的addr,a,b,int.水库.a + b =总计5

C)沤.addr,ret结果的addr,x,返回结果的空间fred = total 4

d)最后一个不是在任何给定点询问激活记录最大所需堆栈大小.它调用sum,它调用barney和barney调用fred,即7 + 5 + 4 = 16.并且16 + a + x =总共18个位置来运行该程序.

请注意,此计算基于我对您的图书惯例的猜测.