0

Postfix & Prefix Increments, how do they work?

So, I'm learning C++, and Postfix and Prefix increments are confusing. How do they work, exactly? It says for Prefix that it increments the value, then proceeds with the expression. The variables given are x = 5 and y = ++x. The answers given are both 6. How does that work, exactly? Wouldn't it be x = 5, and y = 6? The same can be said for Postfix, as it says it evaluates the expression, then begins incrementing. The variables are the same, except y = x++. This time the answers are x = 6 and y = 5. I can't help but think this is backwards.

28th Jun 2018, 3:45 AM
Kenya Martin
Kenya Martin - avatar
1 Réponse
28th Jun 2018, 4:04 AM
Utkαrsh
Utkαrsh - avatar