联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2020-10-17 11:32

CS 320 Fall 2020 Name _________________________________ Last 4 digit of RedID ______

Homework 2

1. Ada Scope Rules (2 pts)

procedure Main is

X: Integer

procedure S1 is

begin -- of S1

Put(X);

end; -- of S1

procedure S2 is

X: Integer

begin -- of S2

X := 10;

S1

end; -- of S2

begin -- of Main

x := 5;

S2

end; -- of Main

2. Variables (2 pts)

Suppose a memory address myaddr contains the bit pattern: 00000000000000000000000000010110

Describe the value retrieved from myaddr when it is accessed by float *fptr, and when it is accessed by

int *iptr.

3. C struct (3 pts)

Given the following declarations:

struct Example {

int data;

char *tag;

};

struct Example *example;

Assume this Ada program was compiled and executed using

static-scoping rules. What value of X is printed in procedure S1?

Under dynamic-scoping rules, what value of X is printed in

procedure S1?

Static Scoping Dynamic Scoping

Output: ______________ _______________

Write the code segment needed to set the data variable to 25, and

the tag string to "Hello World". First, malloc the storage for

an Example struct. The output from this code segment should be:

data = 25, tag = Hello World

4. Given the following program segment:

void foo(int **, int *, int *);

int main(void) {

int x=2, y=4;

int *A=&x, *B=&y, C=2;

foo(&A, B, &C);

return(EXIT_SUCCESS);

}

void foo(int **a, int *b, int *c) { ... }

The system stack begins at address 0x0248ffe0

The addresses of the variables declared in main are:

x: 0x00009012

y: 0x0000900E

A: 0x0000900A

B: 0x00009006

C: 0x00009002

Within the body of the function foo, give the values for the following expressions: (5 pts)

Expression Write address in the form 0xfeedbeef

5. Python (3 pts)

What does the following function output?

def myfunc(y):

x = y

def myinnerfunc():

print(x*x)

myinnerfunc()

myfunc(3) Output _____________

How do you know if this dynamic-scoping rules or static-scoping rules?


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp