tell whether each statement below is valid or invalid.
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
int* ptrA;
int* ptrB;
tell whether each code segment below results in an inaccessible object, a dangling pointer, or neither.
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
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?)