+ 2
Post and pre increment and decrement
if int x is 5 what is x++ x-- ++x --x ?
2 odpowiedzi
+ 3
gud question... well variables are assigned to a value ... while we are using it in any function the pre or post incriment or decriment are useful... let me explain with some php code...
<?php
$a=2;
//now lets go for pre incriment first
echo ++$a;
/* it prints 3 because pre incriment is to +1 before it exicute*/
//now pre decriment
echo --$a;
//it prints 2 as decriment is to subtract 1
//let me explain post incriment
echo $a++;
/*it prints $a value as 2 and then the value of $a changes to 3 */
//last one post decriment
echo $a--;
/*it prints 3 as we post incrimented the value of $a and now its value is decrimented to 2 */
?>
- 1
x++=5
x--=6
++x=6
--x=5