Find the error in each of the following program segments. Assume the following declara- tions and statements:

```
int* zPtr; // zPtr will reference built-in array z int number;
int z[5]{1, 2, 3, 4, 5};
```
a) ++zPtr;
b) // use pointer to get first value of a built-in array
c) // assign built-in array element 2 (the value 3) to number
d) // display entire built-in array z
e) ++z;


a) Error: zPtr has not been initialized.
Correction: Initialize zPtr with zPtr = z; (Parts b–e depend on this correction.)
number = zPtr;
b) Error: The pointer is not dereferenced.
Correction: Change the statement to number = *zPtr;
number = *zPtr[2];
c) Error: zPtr[2] is not a pointer and should not be dereferenced.
Correction: Change *zPtr[2] to zPtr[2].
for (size_t i{0}; i <= 5; ++i) {
cout << zPtr[i] << endl;
}
d) Error: Referring to an out-of-bounds built-in array element with pointer subscript- ing.
Correction: To prevent this, change the relational operator in the for statement to <
or change the 5 to a 4.
e) Error: Trying to modify a built-in array’s name with pointer arithmetic.
Correction: Use a pointer variable instead of the built-in array’s name to accomplish pointer arithmetic, or subscript the built-in array’s name to refer to a specific element.

Computer Science & Information Technology

You might also like to view...

To verify if the DNS service is reachable and operational, use which of the following commands?

a. lookup b. nslookup c. n-slookup d. dns-lookup

Computer Science & Information Technology

Path MTU Discovery uses the __________ protocol.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

What is the term that is used to describe a computer system that could store literary documents, link them according to logical relationships, and allow readers to comment and annotate what they read?

A. WWW B. Internet C. Cascading style sheets (CSS) D. Hypertext

Computer Science & Information Technology

Email bombing, as a form of DoS, is characterized by abuser sending identical message repeatedly to a particular address

a. true b. false

Computer Science & Information Technology