2.5 References (3)

2013-10-07 15:26:14 · 作者: · 浏览: 76

EXERCISES SECTION 2.5

Exercise 2.24: Which of the following definitions, if any, are invalid Why How would you correct them

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

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

Exercise 2.25: Given the preceeding definitions, which, if any, of the following assignments
are invalid If they are valid, explain what they do.

(a) rval2 = 3.14159; (b) rval2 = rval3;

(c) ival = rval3; (d) rval3 = ival;

Exercise 2.26: What are the differences among the definitions in (a) and the assignments
in (b) Which, if any, are illegal

(a) int ival = 0; (b) ival = ri;

const int &ri = 0; ri = ival;

Exercise 2.27: What does the following code print

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