Vidyalelo
PHP · Q71

Operators And Expressions

Programming · PHP · question 71

Q71

What will be the output of the following PHP code ?

A.
1040
Answer
B.
1410
C.
1400
D.
4100

Answer: Option A

Solution

Answer: Option A
Solution:
Understanding the PHP Code:
The code defines a function named 'fun' that takes two arguments, b.
Inside the function:
  The value of $b is changed to 3.
  The function calculates b + a, which simplifies to 0 (because the b and -b cancel each other out).
  The function then returns this result (which is 0).
Outside the function:
  The values of b are initially set to 10 and 4 respectively.
  The function 'fun' is called with 10 and 4 as arguments, and the returned value (0) is assigned to $c.
  Finally, the code prints the values of b, and $c.
Tracing the Output:
$a remains 10 (it is not modified within the function because of pass-by-value).
b).
$c becomes 0 (the return value of the function).
Therefore, the code will print "1040". Correct Option:
The correct answer is Option A: 1040