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

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

3 287 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

Nội dung

Tutorial Data Types (p.2) and Sequence Control Question 1: Generate the result tables for the corresponding programs a) int *p, *q, n, m; Instruction n = 1; //1 m=2; //2 p = &m; //3 q = &n; //4 n ; //5 m++; //6 p = q; //7 q = &m; //8 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 Question 2: a) Draw the tree expresses evaluation order for: i (a – b) / c & (d * e / a – 3) & / - * a b / c - d a e *p N/A *q N/A n 1 0 m N/A 2 3 *p N/A *q N/A n N/A m N/A N/A 1 N/A N/A N/A ii a > b xor c or d a a b c c xor d 17 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 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 = Case i b a Loop times Infinite Protected Infinite Protected Protected protected Protected Infinite Protected Protected Infinite Protected Protected Protected Protected Protected Question 6: a Passed by value: Init After 1st swap After 2nd swap After 3rd swap value 2 2 list {1, 3, 5, 7, 9} {1, 3, 5, 7, 9} {1, 3, 5, 7, 9} {1, 3, 5, 7, 9} value 1 list {1, 3, 5, 7, 9} {2, 3, 5, 7, 9} {3, 2, 5, 7, 9} {3, 1, 5, 7, 9} value 1 list {1, 3, 5, 7, 9} {2, 3, 5, 7, 9} {3, 2, 5, 7, 9} {3, 1, 5, 7, 9} value 1 list {1, 3, 5, 7, 9} {2, 3, 5, 7, 9} {3, 2, 5, 7, 9} {3, 2, 1, 7, 9} b Passed by reference: Init After 1st swap After 2nd swap After 3rd swap c Passed by value-result: Init After 1st swap After 2nd swap After 3rd swap d Passed by name: Init After 1st swap After 2nd swap After 3rd swap

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

TỪ KHÓA LIÊN QUAN

w