200-710 Exam QuestionsBrowse all questions from this exam

200-710 Exam - Question 9


What is the output of the following code?

Show Answer
Correct Answer: A,C

The given code snippet appears to be PHP code. In PHP, when you perform arithmetic operations on strings that contain integers or hexadecimal numbers, PHP attempts to convert these strings to their respective numeric values. The expression is evaluated according to the operator precedence rules, which prioritize multiplication over addition. Evaluating the expression step by step: The code is 'echo "1" + 2 * "0x02";', where the string '"0x02"' is interpreted as '0' because PHP encounters '0x' as a string prefix and ignores it. Therefore, the expression simplifies to '1 + 2 * 0', which results in '1'. Hence, the output of the code is '1'.

Discussion

3 comments
Sign in to comment
[Removed]Option: A
Jun 20, 2020

in PHP 7.1 the result will be 1, so the correct answer is A

thuanptOption: C
Oct 9, 2021

echo "1" + 2 * "0x02"; // 1 echo 1 + 2 * 0x02; // 5

nicky91294Option: A
Jun 27, 2021

Answer is A