PHP Test online


6. What is the output of the following script?

<?php
$a = 10;
$b = 20;
$c = 4;
$d = 8;
$e = 1.0;
$f = $c + $d * 2;
$g = $f % 20;
$h = $b - $a + $c + 2;
$i = $h << $c;
$j = $i * $e;
print $j;
?>


Вариант ответа 1 - A) 128

Вариант ответа 2 - B) 42

Вариант ответа 3 - C) 242.0

Вариант ответа 4 - D) 256

Вариант ответа 5 - E) 342


Comments: Other than the simple math, the % operator is a modulus, which returns whatever the remainder would be if its two operands were divided. The << operator is a left-shift operator, which effectively multiplies an integer number by powers of two. Finally, the ultimate answer is multiplied by a floating point and, therefore, its type changes accordingly. However, the result is still printed out without any fractional part, since the latter is nil. The final output is 256 (Answer D).

Comments

User nameComment
User name
Comment text
Code