ExamVeda
Login
Home
Operators and Expressions
?

Determine output:
void main()
{
      int i=0, j=1, k=2, m;
      m = i++ || j++ || k++;
      printf("%d %d %d %d", m, i, j, k);
}

Answer & Solution
Correct Answer: Option B
In this C program, the expression i++ || j++ || k++ involves the logical OR (||) operator. Here's how it works:

- It evaluates from left to right.
- It stops evaluating as soon as it finds a true condition because in a logical OR operation, if one operand is true, the result is true.

Let's break it down step by step:
- i is initially 0. i++ returns 0 (post-increment), but it increments i to 1.
- j is initially 1. j++ returns 1 (post-increment), and it increments j to 2.
- k is initially 2. k++ returns 2 (post-increment), and it increments k to 3.

Now, the expression is evaluated:
- 0 || 1 is true because one of the operands is true.
- Since the result is true, the evaluation stops.

After the evaluation:
- m is assigned the value 1 because the result is true.
- i is 1 because i was incremented during the evaluation.
- j is 2 because j was incremented during the evaluation.
- k is 2 because k was not incremented further.

Therefore, the output of the printf statement is 1 1 2 2, which corresponds to Option B.
Examveda
Question posted by Examveda
Community

Join the Discussion

5 Comments
Abhijeet Kulkarni
Abhijeet Kulkarni 3 years ago
need video explaination basic
Sandip Majumdar
Sandip Majumdar 5 years ago
Its very fine
Ajinkya Londhe
Ajinkya Londhe 9 years ago
its correct ohh yeahh
Examveda
Examveda 10 years ago
Hello Sonika,
If you read the solution properly you will get to know why 'k' is still remain 2.
When ever Operator || found in expression it work from left to right and stopped at non zero value.
Sonika Saini
Sonika Saini 10 years ago
why k++ is not increment the value of k