PHP Questions and Answers for Campus interviews on “Operators – 4”.
1. What will be the output of the following PHP code?
a) 24
b) 3.7
c) 3.85
d) 0
Answer: a
Clarification: Operator precedence order must be followed.
2. What will be the output of the following PHP code?
a) no output
b) error
c) 6
d) 7
Answer: b
Clarification: Operator ++ can be done only on variables.
3. What will be the output of the following PHP code?
a) 5
b) error
c) 6
d) 7
Answer: b
Clarification: Operator ++ can be done only on variables.
4. What will be the output of the following PHP code?
a) 5
b) error
c) 6
d) 7
Answer: a
Clarification: Operator precedence followed.
5. What will be the output of the following PHP code?
a) 5
b) error
c) 6
d) 7
Answer: c
Clarification: Operator precedence followed.
6. What will be the output of the following PHP code?
a) 5
b) error
c) 6
d) 7
Answer: a
Clarification: Operator precedence followed,incremented after display.
7. What will be the output of the following PHP code?
a) 1
b) 0
c) 2
d) 3
Answer: d
Clarification: Evaluation done from right to left.
8. What will be the output of the following PHP code?
a) 16
b) 06
c) 15
d) 05
Answer: a
Clarification: 1&&0||1 is evaluated to 1 and the a is also pre incremented to 6.
9. What will be the output of the following PHP code?
a) 1
b) 0
c) 2
d) 3
Answer: a
Clarification: $var = ++$var returns 1(success).
10. What will be the output of the following PHP code?
a) 3
b) 4
c) 5
d) error
Answer: d
Clarification: First pre increment is done and the result is a number, thus post increment cannot be performed on it.
