Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between (++i) and (i++)

In C++ I understand that (++i) should return a reference to i because the need of concatenation of operators, but what I can't figure out is:

Why (i++) should return i by value?

Can anyone please clarify.

like image 520
bks Avatar asked Jun 18 '10 19:06

bks


People also ask

What's the difference between i and i?

Initially in French and also in Afrikaans, Catalan, Dutch, Galician, Southern Sami, Welsh, and occasionally English, ⟨ï⟩ is used when ⟨i⟩ follows another vowel and indicates hiatus in the pronunciation of such a word.

What is the difference between i and i?

Ibero-Romance. In Ibero-Romance languages, the "í" is not considered a letter, but the letter "i" with an accent. It is used to denote an "i" syllable with abnormal stress.

What's the difference between i and i sounds?

As indicated by the /:/ part of its symbol, /i:/ is a longer sound than /ɪ/ and pronouncing it this way can help distinguish between the two in the pairs of words below. You will also notice, however, that /ɪ/ does not have a dot over it, making it a different mouth position from /i:/.

What is the difference between EE and i?

1. EE bonds are issued at a discount (50%) of their face value, while I bonds are offered at face value. 2. EE bonds only have a varying interest rate, while I bonds have both fixed and varying interest rates.


1 Answers

i++ returns a value because it is returns the old value of i, while i is increased by 1.

A basic implementation of this would be:

int i++() {
  int old = i;
  i = i + 1;
  return old;
}

So, if it returned a reference, it would be the wrong value... since i's value has been incremented!

like image 114
Stephen Avatar answered Sep 24 '22 00:09

Stephen