Question: Consider the simple C or C++ language statements: a ++; and a = a + 1; For integer variables they are completely equivalent. For pointers

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.)

Step by Step Solution

3.32 Rating (161 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ANSWER There are several potential problems that can occur when mixing the expressions a and a a 1 i... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction To Software Engineering Questions!