What is the output of the following code? int main () { int i = -1 ; j = 1 , k = 0 , m ; m = i++ || j++ && k++ ; printf ("nn%d %d %d " , i , j , k , m ) ; }

This question is related to Wipro Interview

Showing Answers 1 - 9 of 9 Answers

yogesh

  • Nov 21st, 2005
 

Ans is:

0 1 0 1

  Was this answer useful?  Yes

Sarada

  • Feb 25th, 2006
 

  • i=0 ----> (i=-1 and i++=0)
  • j=2 ----> (j=1 and j++=2)
  • k=1 ----> (k=0 and k++=1)
  • m=0 ----> (m= -1 || 1 && 0  => m= 1 || 1 && 0 => m=1 && 0  => m=0)

Answer is : 0 2 1 0

  Was this answer useful?  Yes

setu

  • Mar 9th, 2006
 

anwer is 0,2,1,1

  Was this answer useful?  Yes

purani

  • Jun 18th, 2006
 

its error.watch out for the semicolon next to -1.so j,k,m are unassigned

amar

  • Apr 12th, 2007
 

0 1 0 1

  Was this answer useful?  Yes

anjani

  • Apr 30th, 2007
 

nn010

  Was this answer useful?  Yes

bharat_bagana

  • Jul 3rd, 2007
 

If it is post increment, after && operation the expression is not executed if the whole exprssion give the value to the right side.
In examining the value of 'm' it does not see the value, it sees ,wheather the value is '0' or not, and it does the evaluation. So m is always either 'o' or '1'.
The answer is  0201

  Was this answer useful?  Yes

mari

  • Jul 28th, 2007
 

m = i++ || j++ && k++ ;
here && has the higher priority than || so make it as
m = i++ ||( j++ && k++ )
since it is || if any one of the condition is true other is neglected
so evaluating first condition i++.  i increases to 2.
other condition is neglected.
so the value of i is =-1+1=0
j &k remains as it is
j    =1
k    =0
since the condition is true
m is assigned 1
m=1
so the ans is 0,1,0,1

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions