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: 12 Last Update: February 11, 2010   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: nagarjunat
 
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;

Above answer was rated as good by the following members:
gia.sindhu, rajeshmeena21
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
April 20, 2005 07:14:41   
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 | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
May 07, 2005 06:51:59   
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 | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 21, 2005 23:58:47   
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 | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
September 02, 2005 04:14:33   
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 4Overall Rating: -4    
November 17, 2005 22:17:51   
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 | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
November 20, 2005 02:15:33   
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   
Rahul Gupta        

RE: What is the value of y in the following code?x...
ans (a)7
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 02, 2008 04:52:12   
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   
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 | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
December 08, 2009 08:18:43   
vishwanathpillay Member Since: July 2008   Contribution: 13    

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 line:

LINE 1: if(x 6)
LINE 2: y 7;
LINE 3: else
LINE 4: y 1;

In the line 1 it is not assigning any values its just a conditional operator which checks the value of x.

If line 1 is true then value can be 7 BUT

In this case the value will be 1 bcoz its is just checking the condition

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

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

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

Page copy protected against web site content infringement by Copyscape