196k views
2 votes
Look at the following statement:

sum += *array++;

This statement ________.
A) is illegal in C++
B) will always result in a compiler error
C) assigns the dereferenced pointer's value, then increments the pointer's address
D) increments the dereferenced pointer's value by one, then assigns that value
E) None of these

1 Answer

5 votes

Final answer:

The given statement, 'sum += *array++;' in C++, assigns the dereferenced pointer's value to the sum and then increments the pointer's address.

Step-by-step explanation:

The given statement, sum += *array++; in C++, is valid code that combines several operators. Here's what each part of the statement does:

  1. array++: This increment operator increases the pointer's address by one.
  2. *array: The dereference operator retrieves the value at the memory address pointed to by 'array'.
  3. +=: This compound assignment operator adds the value on the right side to the sum on the left side and updates the sum.

Therefore, the given statement sum += *array++; assigns the dereferenced pointer's value to the sum and then increments the pointer's address.

User Msmani
by
7.3k points