487 views

2 Answers

Best answer
3 votes
3 votes

m= ++i && ++j || ++k ; here && and operator and || is or operator. 

In logic we study about if one part is true in expression when OR oprator come whole expression is true . same concept used here  Which is called as Short circuit. [ but with && oprator whe have to calculate all parts]

m=( ++i && ++j) || ++k;

 So if ( ++i && ++j) ii.e. nonzero  ] part is true no need to check ++j 

( ++i && ++j) will make i= -2 and j= 3 whch rsults nonzero value so no need to perform ++k; Ans m will contain 1.

So answer is -2 , 3, 0, 1

selected by
1 votes
1 votes

I would like to explain the code in detail:

++i means Preincrement , means before evaluation of i we have to increase its value by 1.

.. && .. means that the conditions left to it and right to it must be valid.

.. || .. menas that either left condition or right condition to it must exist , not both simultaneously.

So now here we go:

Initial values of i= -3 , j=2 , k=0 

and m = ++i && ++j || k 

so in answer either we should have i= -2 , j =3 or k =1  , Remember we cannot have i= -2 , j =3 and k=1 , either the answer should contain -2,3,0  or -3,2,1.

seeing till this we could easily say that A is the right Option..

Peace..

No related questions found