GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Placement Papers  >  TCS  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 8 of 87    Print  
What is the value of y in the following code?
x=7;y=0;
if(x=6)
y=7;
else
y=1;
a.7
b.0
c.1
d.6
C



  
Total Answers and Comments: 9 Last Update: June 21, 2009   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
April 20, 2005 07:14:41   #1  
Sarada        

RE: What is the value of y in the following code?x=7;y=0;if(x=6)y=7;else y=1;a.7b.0c.1d.6
Answer for this is : a
that is y value is 7. Here assignment statement get executed in if condition which evaluates to true so 7 will be assigned to y.

 
Is this answer useful? Yes | No
May 07, 2005 06:51:59   #2  
a tirupathi rao        

RE: What is the value of y in the following code?x=7;y=0;if(x=6)y=7;else y=1;a.7b.0c.1d.6
if(x 6) meens in this x will be assigned to 6
and the condition is non zero value.
so if part will excute and y will be assigned to 7. thus the y value is 7.

 
Is this answer useful? Yes | No
July 21, 2005 23:58:47   #3  
rohit        

RE: What is the value of y in the following code?x=7;y=0;if(x=6)y=7;else y=1;a.7b.0c.1d.6
answer is :a
value of y 7

 
Is this answer useful? Yes | No
September 02, 2005 04:14:33   #4  
Ragu        

RE: What is the value of y in the following code?x=7;y=0;if(x=6)y=7;else y=1;a.7b.0c.1d.6
hello how r u saying y 7 if condition itself false than it will come to else statement only.
Ans:C

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 2Overall Rating: -2    
November 17, 2005 22:17:51   #5  
Timothy        

RE: What is the value of y in the following code?x...

A

answer is y 7

Now this will assign 6 to x.

If we print the value of x It will display 6.

if the compailer saw if(x 6) it will simply assign 6 to x

but If we mistakenly give if(6 x) it will display an error

So It's better to use if(6 x)


 
Is this answer useful? Yes | No
November 20, 2005 02:15:33   #6  
Rohan Member Since: November 2005   Contribution: 11    

RE: What is the value of y in the following code?x...

x 7 and y 0

now if(x 6)

//assigns 6 to x and what is >0 in if is true so condition is true

so y 7


 
Is this answer useful? Yes | No
July 01, 2006 05:32:53   #7  
Rahul Gupta        

RE: What is the value of y in the following code?x...
ans (a)7
 
Is this answer useful? Yes | No
July 02, 2008 04:52:12   #8  
prat8759 Member Since: July 2008   Contribution: 2    

RE: What is the value of y in the following code?x=7;y=0;if(x=6)y=7;else y=1;a.7b.0c.1d.6
correct ans is A: y 7.....bcoz condition is if(x 7) (assignment)and not (x 7) (comparison)
 
Is this answer useful? Yes | No
June 21, 2009 02:27:03   #9  
nagarjunat Member Since: October 2008   Contribution: 3    

RE: What is the value of y in the following code?x=7;y=0;if(x=6)y=7;else y=1;a.7b.0c.1d.6
Here the statement if(x 6) is true because this is not a conditional operator it assigns 6 to x so it is true the if condition is true
then y 7;

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape