Examveda
Examveda

In an expression involving || operator, evaluation
I.   Will be stopped if one of its components evaluates to false
II.  Will be stopped if one of its components evaluates to true
III. Takes place from right to left
IV.  Takes place from left to right

A. I and II

B. I and III

C. II and III

D. II and IV

E. III and IV

Answer: Option D

Solution(By Examveda Team)

In C, the logical OR operator (||) behaves as follows:

If the first operand evaluates to true, the entire expression is considered true, and further evaluation is stopped.
If the first operand evaluates to false, the evaluation continues with the second operand. If the second operand evaluates to true, the entire expression is considered true.
If both operands evaluate to false, the entire expression is considered false.

Based on this behavior, the evaluation doesn't stop when one of its components evaluates to true (contrary to option II). Instead, it stops when one of its components evaluates to false.

Regarding option IV, the evaluation of the logical OR operator (||) is left-to-right, so option IV is correct.

So, the correct answer is indeed Option D: II and IV, which means the evaluation will stop when one of its components evaluates to false, and the evaluation takes place from left to right. Thank you for pointing out the correction.

This Question Belongs to C Program >> Operators And Expressions

Join The Discussion

Comments ( 3 )

  1. Dinithi Sahanika
    Dinithi Sahanika :
    2 years ago

    What it means "takes left to right"

  2. Pratik Shete
    Pratik Shete :
    6 years ago

    thanks wani!

  3. Wani Parvaiz
    Wani Parvaiz :
    6 years ago

    Logical || Operator evaluates to true if any one of input is true, so it'll not stop on if any one input is true or false. And one more thing is that the expression is evaluated from left to right. So your option is not appropriate and its answer must be E part.

Related Questions on Operators and Expressions