What is the difference between x-- and --x?
Answers
This question is for kids
x-- means postfix increment
The value of x remains same (i.e., (your value of x) before action
--x means prefix increment
The value of x decreases by 1 (i.e., (your value of x)
Understood!!
Answer:
x-- in this the value of the variable changes after execution , it is also known as post fix
--x and thus the value of the variable changes before the execution, it is also known as prefix
Explanation:
for for example
X is equals to 2
find the value of x in
x= --x + x-- +--x
x= 4+ x-- + --x
x= 4+4+--x
x=8+2
x=10
for explaining
step 1
put the value of--x that is the prefix operator so the value of --x will be 5 - 1 that is 4.
step 2
put the value of x-- that is the post fix operator so the value of x--will be Britain has 4 in the equation but after defining the variable x--the value of x will be 4 - 1 that is 3
step 3
again put the value of--x but now it will not be 4 -1 it will be 3 - 1
because the value of x minus minus is not shown in the equation but after defining the variable its value is changed from 4to 3 and now buy again defining another variable we will use its value as 3 not 4