Answer the following statements true (T) or false (F)

1. One can use the & operator to extract the value that a pointer points to.
2. When declaring several pointer variables, there must be one pointer declarator * for each pointer variable.
3. Dangling pointers present no problem in C++
4. Dynamic variables or dynamically allocated variables in C++ are created and destroyed according to the program’s needs.
5. There should eventually be a call to the operator delete on a pointer that
points to the memory allocated by each call to new.

1. False
The operator is the dereferencing operator, *. This says “follow the pointer to the storage place” or “the variable pointed to by …”
2. True
Consider this definition of p1, p2 and p3 as pointer to doubles:
```
double *p1, *p2, *p3;
```
There must be one * for each pointer variable defined.
3. False
A dangling pointer occurs when several pointers point to the same chunk of allocated freestore memory. If one of the pointers has had the delete
pointer applied to it, releasing the freestore memory, the other pointers are said to be dangling. Because the pointer that had delete applied to it most of the time isn’t
changed by the delete operation (not guaranteed by any means), a deleted pointer is frequently called a ‘dangling pointer.’
4. True
Dynamic variables are unaffected by function calls or function return. This is not true of local pointer variables that may point to dynamic variables. Consequently, in a poorly written program, a local pointer can go out of scope and the dynamic variable to which the pointer points may be lost.
5. True
Pointer variables are usually local variables. Memory allocated on the free store using the new operator remains allocated whether you use it or even have a pointer pointing to it. If the pointer that points to the allocated memory dies with the end of a function or a block, the memory allocated is locked away so that no one can use it until the program terminates.

Computer Science & Information Technology

You might also like to view...

In Outline view, body text is text that does not have a heading style applied

Indicate whether the statement is true or false

Computer Science & Information Technology

The method used to predict future values by analyzing the relationships between two or more variables is the ________

A) R-squared value B) correlation coefficient C) regression analysis D) intercept coefficient

Computer Science & Information Technology