Consider the simple C or C++ language statements: a ++; and a = a + 1; For

Question:

Consider the simple C or C++ language statements:
a ++;
and
a = a + 1;

For integer variables they are completely equivalent. For pointers in C and C++, the assignment a = a + 1 indicates pointer arithmetic; the pointer a (which represents a location) is set to the location computed by the expression a + sizeof(type of expression pointed to by a)

This equality is the basis for the equivalence of a[1] and *(a + 1) in C.

Unfortunately, there are problems with the use of these notations interchangeably in C++, due to the design of the standard C++ library. List the problems that can occur when mixing the expressions a++ and a = a + 1 in C++ programs. Do the same for a — and a = a – 1. (Recall that the standard C++ library offers five kinds of iterators: input, output, forward, bidirectional, and random access.)

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: