Answer the following statements true (T) or false (F)
1. A pointer is a variable that holds the address of some other location in memory.
2. Pointer variables are just memory addresses and can be assigned to one another without regard to type.
3. 3. The declaration below declares three pointer variables of type pointer to double that is, a pointer of type (double*)
double* p1, p2, p3;
4. A pointer is an address, an address is an integer, but a pointer is not an integer.
5. 5. You can get a pointer value to initialize a pointer variable from an object of an appropriate type with the “address-of” operator, &.
1. True
Computer memory is composed of addressable chunks of information called bytes. A pointer value is the memory address stored in a pointer variable.
2. False
A pointer variables, like everything else in C++ is typed, and that typing is enforced strongly. A pointer variable of type double* cannot normally hold a pointer value of type int* for example.
3. False
This declares one pointer variable, p1, and two double variables, p2 and p3. The * binds more closely to the variable, not to the type. In spite of this, the usually style puts the asterisk against the type.
To get three pointer variables, one must write
```
double *p1, *p2, *p3;
```
or better, declare the three pointer variables on separate lines
```
double* p1;
double *p2;
double *p3;
```
4. True.
Not crazy, rather this is an abstraction. The type system in C++ is sufficiently strong that it requires that you not assign pointer values to other types nor other types to pointers (without a cast, but that tells the compiler you know what you are doing, so it lets you.)
5. True
Every object has a value and an address. The & “address-of” operator extracts the address to make it available to initialize a pointer variable of appropriate type. Example: int x; int *ptrX = &x;
You might also like to view...
Match the following keyboard navigation controls to their function:
I. Home A. beginning of the document II. End B. end of the document III. Ctrl+End C. top of the previous page IV. Ctrl+PgUp D. end of a line V. Ctrl+Home E. beginning of a line
Which of the following variables names is considered Camelback notation?
a. x b. PiSquared c. leNGth d. payRate e. city_block