πŸ“Š C++
Q. Evaluate the following expression :
Code:
(false && true) || false || true
  • (A) Compilation error
  • (B) 0
  • (C) false
  • (D) 1
πŸ’¬ Discuss
βœ… Correct Answer: (D) 1

Explanation:

Let's evaluate the expression step by step:

Expression:

(false && true) || false || true

In C (and most C-like languages), the logical operators work like this:

  • && (logical AND): true if both operands are true
  • || (logical OR): true if any one operand is true
  • false is equivalent to 0
  • true is equivalent to 1

So replacing the keywords with their integer equivalents:

(0 && 1) || 0 || 1

Step-by-step evaluation:

0 && 1 = 0
(because both need to be true (non-zero), but the first is false (0))

Now the expression becomes:

0 || 0 = 0
Then, 0 || 1 = 1

βœ… Final Result: 1

Hence, the correct answer is: (D) 1

0 || 0 || 1

Explanation by: Mr. Dubey

Let's evaluate the expression step by step:

Expression:

(false && true) || false || true

In C (and most C-like languages), the logical operators work like this:

  • && (logical AND): true if both operands are true
  • || (logical OR): true if any one operand is true
  • false is equivalent to 0
  • true is equivalent to 1

So replacing the keywords with their integer equivalents:

(0 && 1) || 0 || 1

Step-by-step evaluation:

0 && 1 = 0
(because both need to be true (non-zero), but the first is false (0))

Now the expression becomes:

0 || 0 = 0
Then, 0 || 1 = 1

βœ… Final Result: 1

Hence, the correct answer is: (D) 1

0 || 0 || 1

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
225
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Ram Sharma
Publisher
πŸ“ˆ
82%
Success Rate