- What does the test() print? Do a careful hand simulation.
void test()
{
int* s;
int* p = new int;
int* q = p;
int* r = new int;
*p = 8;
s = p;
*q = 25;
*r = *s;
q = r;
cout << "*p = " << *p << endl;
cout << "*q = " << *q << endl;
cout << "*r = " << *r << endl;
cout << "*s = " << *s << endl;
}
- When is a variable that is local to a function destroyed (or
deallocated)?
- When is a variable that is allocated using new destroyed (or
deallocated)?
- What is the difference between the physical size of an array
and the logical size of an array?
- What is a dangling pointer?
- What is a memory leak?
- The NULL pointer is memory address 0. What happens if you write
execute
char* p;
p = NULL;
*p = 'x';
- Can an array be allocated using new? If so, how would you
allocate an array of 20 characters, and make pointer variable p point to
that array?
- What happens if you perform the following? Will it compile? Is
it a reasonable program fragment?
char *s;
cin >> s;
cout << s;
- If Giraffe is a type, then expression new Giraffe returns a
pointer. What is the type of the pointer?
- How can you compare two strings to see if they are the same?
Write a statement that sets integer variable x to 1 just when two arrays
s and t hold the same string.
- How can you copy the null-terminated string in array s into
array d?