why the correct answer is 17 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why the correct answer is 17

i think it should be 18 because the decreament after the print !!!

10th Sep 2016, 8:34 AM
Hisham Nabil Alsaifi
Hisham Nabil Alsaifi - avatar
7 Answers
+ 2
Because the decrement is done after the affectation of the value of $num to $num1 (post-decrement). Hence $num1 holds 18. (Edited, I made some mistakes here.)
10th Sep 2016, 9:11 AM
Zen
Zen - avatar
+ 1
Hum, no, the decrement is clearly one line before the print. <?php $num = 18; $num--; echo $num; ?> If the decrement is done separately, whether it is pre or post doesn't matter.
10th Sep 2016, 9:09 AM
Zen
Zen - avatar
0
okay but why in this the output is 18? <?php $num=18; $num1=$num--; echo $num1 ; ?>
10th Sep 2016, 8:46 AM
Hisham Nabil Alsaifi
Hisham Nabil Alsaifi - avatar
0
got it 😀 thank you 😍
10th Sep 2016, 9:07 AM
Hisham Nabil Alsaifi
Hisham Nabil Alsaifi - avatar
0
because in that case, is post-decrement it means that first it assigns the value(18) to num1 and then does the decrement to num. if you write: ... echo $num1; echo $num; ?> it will show you 18 and 17
13th Sep 2016, 8:59 PM
Billy
Billy - avatar
0
check your application, i think the app have error let's try at playground i was try. just search "Answer question operand" <?php $test=20; $test1=$test--; echo $test1; ?> output is 19
24th Sep 2016, 2:28 PM
Muhamad Iqbal Nurmanditya
Muhamad Iqbal Nurmanditya - avatar
0
17 is answer
30th Dec 2016, 7:04 PM
rahul singh
rahul singh - avatar