Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which is executed quickly?
 

  • A.++p
  • B.p++
  • C.Both
  • D.P+1

Answer: C

Correct answer: Both

On any modern compiler ++p and p++ compile to the same machine code when the result is discarded, as in a for loop’s third clause - the optimiser sees that the old value is unused. The historical preference for ++p matters for C++ iterators, where p++ must copy the object before incrementing it.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.