+ 2

Post and pre increment and decrement

if int x is 5 what is x++ x-- ++x --x ?

5th Feb 2017, 9:42 AM
Richu Thankachan
Richu Thankachan - avatar
2 ответов
+ 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 */ ?>
5th Feb 2017, 10:05 AM
ram b
- 1
x++=5 x--=6 ++x=6 --x=5
5th Feb 2017, 3:00 PM
deepak joshi
deepak joshi - avatar