Computer Science, asked by prathameshwankhede0, 1 month ago

explain the difference between prefix and postfix operator​

Answers

Answered by Jyotij1912
3

Answer:

In the prefix version (i.e., ++i), the value of i is incremented, and the value of the expression is the new value of i. So basically it first increments then assigns a value to the expression.

In the postfix version (i.e., i++), the value of i is incremented, however, the {value|the worth} of the expression is that the original value of i. So basically it first assigns a value to expression and then increments the variable.

Answered by Mɪʀᴀᴄʟᴇʀʙ
10

\begin{lgathered}\huge{\underline{\color{green}{\textsf{\textbf{Answer}}}}} \\\end{lgathered}

→ The postfix increment ++ does not increase the value of its operand until after it has been evaluated. The value of i++ is i.

→ The prefix decrement increases the value of its operand before it has been evaluated. The value of --i is i - 1.

Prefix increment/decrement change the value before the expression is evaluated. Postfix increment/decrement change the value after.

So, in your case, fun(10) returns 10, and printing --i prints i - 1, which is 9.

Similar questions