Beruflich Dokumente
Kultur Dokumente
Spring - 2005
SOLUTION
4. What values should you choose when testing a function you wrote?
o. Values that think will succeed p. Values that think will fail q. Values that are border cases r. Randomly generated values s. All of the above
6. Which of the following assigns the address of value to the pointer p1?
z. *p1 = &value; aa. p1 = value; bb. p1 = &value; cc. &p1 = *value;
7. What is the output of the following code fragment? int* p1 = NULL ; int* p2 = NULL ; *p1 = 3 ; *p2 = 5 ; p2 = p1 ; cout << *p2 << endl ;
dd. 3 ee. 5 ff. NULL gg. This is an error, a segmentation fault
8. What is the output of the following code? int *p1, *p2; p1 = new int; p2 = new int; *p1=11; *p2=0; p2=p1; cout << *p1 <<" " << *p2 << endl;
hh. 0 11 ii. 11 0 jj. 0 0 kk. 11 11 ll. Error, this is a segmentation fault
9. What is the output of the following code fragment? int v1=2, v2=-1; int* p1; int* p2; p1 = &v1; p2 = &v2; p2 = p1; cout << *p2 << endl;
mm. 2 nn. -1 oo. -2 pp. 1
10. Given that p1 is a pointer to a string, which of the following are legal statements?
qq. p1 = new int; rr. cout << *p1; ss. p1 = new char[10]; tt. *p1 = new string; uu. all of the above vv. B and D