1. Trang chủ
  2. » Thể loại khác

bài tập Data Types (p.2) and Sequence Control PPL HCM

3 288 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 3
Dung lượng 39,2 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Operands are evaluated left to right.7 b.. Operands are evaluated right to left.12 Question 5: There are 2 variables subject to changes inside the loop: i, b, and a, which hold the va

Trang 1

Tutorial 5 Data Types (p.2) and Sequence Control

Question 1:

Generate the result tables for the corresponding programs

a)

int *p, *q, n, m;

n = 1; //1

m=2; //2

p = &m; //3

q = &n; //4

n ; //5

m++; //6

p = q; //7

q = &m; //8

Instruction *p *q n m

1

2

3

4

5

6

7

8

N/A

2

3

0

N/A

1

0

3

1

0

N/A

2

3

b)

int *p, *q, n, m;

p = new int; //1

*p = 1; //2

q = p; //3

p = &m; //4

m = *q; //5

n = *p; //6

delete q; //7

m = *q+*p; //8

Result table:

Instruction *p *q n m

1

2

3

4

5

6

7

8

N/A

1

N/A

1 N/A

N/A

1

N/A

N/A

1

N/A

1 N/A

Question 2:

a) Draw the tree expresses evaluation order for:

i (a – b) / c & (d * e / a – 3)

/

&

d e

*

/

a

-

3

Trang 2

ii a > b xor c or d <= 17

b) Convert above expressions to Polish prefix and postfix forms

In Polish prefix notation:

 & / - a b c - / * d e a 3

 or xor > a b c <= d 17

In Polish postfix notation:

 a b – c / d e * a / 3 - &

c) a b > c xor d 17 <= or

Question 3:

if (a>0) {

if (sqrt(a) > b) {

return 1;

}

}

else if (a==0) return 2;

else if (b/a > 1) return 2;

Question 4:

What is the value of x after the assignment statement in main, assuming

a Operands are evaluated left to right.7

b Operands are evaluated right to left.12

Question 5:

There are 2 variables subject to changes inside the loop: i, b, and a, which hold the value

of i, first and lastrespectively So the number of cases to analyze is 23 = 8

6 Protected Protected Infinite

8 Protected Protected Protected 2

>

c

xor

or

d

<=

17

Trang 3

Question 6:

a Passed by value:

After 1st swap 2 {1, 3, 5, 7, 9} After 2nd swap 2 {1, 3, 5, 7, 9} After 3rd swap 2 {1, 3, 5, 7, 9}

b Passed by reference:

After 1st swap 1 { , 3, 5, 7, 9} After 2nd swap 1 { , 2, 5, 7, 9} After 3rd swap 2 {3, 1, 5, 7, 9}

c Passed by value-result:

After 1st swap 1 { , 3, 5, 7, 9} After 2nd swap 1 { , 2, 5, 7, 9} After 3rd swap 2 {3, 1, 5, 7, 9}

d Passed by name:

After 1st swap 1 { , 3, 5, 7, 9} After 2nd swap 1 { , 2, 5, 7, 9} After 3rd swap 2 {3, 2, 1, 7, 9}

Ngày đăng: 14/11/2015, 19:43

TỪ KHÓA LIÊN QUAN

w