[ fromfile: memoryaccess-questions.xml id: memoryaccess-questions ]
What is defined in the following statement?
int* p, q;
p
is an int*
, while q
is an int
.
What is a memory leak? How does it happen?
Compare the way that +
, -
, ++
, and --
operators work on pointers with the way that they work on int
or double
.
With pointers, those operators can only be used if the pointer holds the address of the first element of an array and provided that the results stay within the context of the array. The second operand of +
and -
must be an int n
and the result of the operation will be an address equal to the original address +
or -
n times the size of the type of the "pointed-to" thing. The unary increment/decrement operators work similarly, but with a built-in second operand of 1
.
What happens if delete
is applied to a pointer that has just been deleted?
The results are undefined - heap corruption is likely.
When an array is passed to a function as a parameter, what is copied onto the stack?
The address to the first element in the array.
What is dynamic memory? How do you obtain it in C++?
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |