17

Knowing a language helps in programming class

Comments
  • 0
    Although I'm not sure why my answers are incorrect 🙄
  • 0
    Apparently, my answers were correct :s why did PHP get it wrong?
  • 1
    look up postincrement
  • 2
    @uziiuzair maybe for $b++, it increased your variable. You should use $b+1 instead
  • 0
    @crisz possible. I'll have a look at it in a while as well as try @crystalclear 's suggestion
  • 0
    the difference between pre and postincrement is:
    a = 5;
    a++; // output is 5, a is 6
    ++a; // output is 7, a is 7
  • 0
    @crisz is also correct
  • 0
    b++ will be evaluated before incrementing. For example:
    $b = 5
    $c = 6

    $ans = $b++ + $c ==> 5 + 6 at evaluation
    // $ans is 11
    //$b is now 6
  • 1
    How were your answers correct and PHP wrong? PHP can't be wrong if you trying to manually determine what results PHP would produce. Your teacher is pulling your leg. Maybe give him/her a run down on what you learnt about post-incrementing.
  • 1
    @retrix actually, after my last comment about being correct.. I have yet to believe it was correct. I'll be coding the entire process to see why the answers were different.

    The answers were completely different when done manually.
Add Comment