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.

a tirupathi rao

May 7th, 2005

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.

rohit

Jul 21st, 2005

answer is :a "value of y =7"

Ragu

Sep 2nd, 2005

hello how r u saying y=7, if condition itself false than it will come to else statement only. Ans:C

Timothy

Nov 17th, 2005

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

The value of y is 7. The condition in if loop if(x=6) is true since the variable x is assigned the value 6 as an assignment operator(=) is used, not a comparison operator(==). so the value of y is 7.

Correct Answer is Y=7
Because if(x=6) it means we are assigning value 6 in x. So condition becomes if(6) and if statement is always executed when there is a positive value inside the braces. So Y=7 will be executed. Now if part is true then no need to run else part. So final value of Y remains 7.

abc

Sep 4th, 2011

ans: y=7
since in if clause '=' is used and not'==' , it's a successful assignment operation.
it returns y=7 after comin across a true value and hence y is 7

## 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

This question is related to TCS Interview## Related Answered Questions

## Related Open Questions