Back to questions
JuniorTheoryCommon
What does the program print?
<?php
echo 7 / 2, ' ', intdiv(7, 2), ' ', -7 % 3, ' ', 2 ** 3, "\n";3.5 3 -1 8
- Expecting
7 / 2to give3, as integer division does in many languages: in PHP/returns a float when the division is not exact, andintdiv(7, 2)is the way to get3. - Expecting a non-negative remainder, as in math: in PHP
%takes the sign of the dividend, so-7 % 3is-1.
- What does
intdiv(-7, 2)return, and why? - Which type does
10 / 5return,intorfloat?