< previous page page_1037 next page >

Page 1037
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
typedef PersonType* PtrType;

PersonType onePerson;
PtrType    ptr = &onePerson;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
tell whether each statement below is valid or invalid.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. strcpy(ptr.lastName, Alvarez);
b. strcpy((*ptr).lastName, Alvarez);
c. strcpy(*ptr.lastName, Alvarez);
d. strcpy(ptr->lastName, Alvarez);
e. strcpy(*ptr->lastName, Alvarez);
4. What C++ built-in operation releases the space reserved for a dynamic variable back to the system?
5. Given the declarations
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int* ptrA;
int* ptrB;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
tell whether each code segment below results in an inaccessible object, a dangling pointer, or neither.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. ptrA = new int;             d. ptrA = new int;
   ptrB = new int;             ptrB = new int;
   *ptrA = 345;                *ptrA = 345;
   ptrB = ptrA;                *ptrB = *ptrA;

b. ptrA = new int;             e. ptrA = new int;
   *ptrA = 345;                ptrB = new int;
   ptrB = ptrA;                *ptrA = 345;
   delete ptrA;                ptrB = new int;
   *ptrB = *ptrA;              *ptrB = *ptrA;
c. ptrA = LocationOfAge();
where function LocationOfAge is defined as
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int* LocationOfAge()
{
int age;

cout << Enter your age: ;
cin >> age;
return &age;
}
6. The only operation that affects the contents of a reference variable is initialization. (True or False?)
7. Given the declarations
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int n;
int& r = n;

 
< previous page page_1037 next page >