2.3 Compound Types (3)

2013-10-07 16:18:35 · 作者: · 浏览: 73

EXERCISES SECTION 2.3.1

Exercise 2.15: Which of the following definitions, if any, are invalid Why

(a) int ival = 1.01; (b) int &rval1 = 1.01;

(c) int &rval2 = ival; (d) int &rval3;

Exercise 2.16: Which, if any, of the following assignments are invalid If they are valid, explain what they do.

  1. int i = 0, &r1 = i; double d = 0, &r2 = d;  

(a) r2 = 3.14159; (b) r2 = r1;

(c) i = r2; (d) r1 = d;

Exercise 2.17: What does the following code print

  1. int i, &ri = i;   
  2. i = 5; ri = 10;   
  3. std::cout << i << " " << ri << std::endl;