What is the value of y in the following code?
x=7;y=0;
if(x=6)
y=7;
else
y=1;

Answers were Sorted based on User's Feedback



What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;..

Answer / mahendra giri

y will be 7 because in the if condition we have assigned
value 6 on x not ==,so ans of
y =7

Is This Answer Correct ?    40 Yes 2 No

What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;..

Answer / deepa

y = 7

Is This Answer Correct ?    22 Yes 3 No

What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;..

Answer / piyush

its looks logically incorrect,but in c anc c++ if any such
incident occurs like if(x=6), this condition is always
treated as true

will give a warning ,but will execute this as considering
the if condition as true

ANSWER to this question is y=7

Is This Answer Correct ?    15 Yes 0 No

What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;..

Answer / gg

Ans: 7

Coz all non-zero statements are treated as true.
code can be written as..

if(TRUE)/*x=6 is a non-zero*/
Y=7;
else
y=1;

Note: To compare,have to use '==' operator.'=' is an
assignment operator.

Is This Answer Correct ?    12 Yes 0 No

What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;..

Answer / shruti

y = 7..

Is This Answer Correct ?    5 Yes 0 No

What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;..

Answer / balaji jayakumar

y=7 because if condition doesnt fail... so the immediate
statement after if will be executed and 7 gets printed. It
is quite certain only if "if" fails else will be be opted
for. so y=7... no error statements will occur.. i have tried
it in c.

Is This Answer Correct ?    3 Yes 0 No

What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;..

Answer / priya

Logically it is wrong ,because relational operator(==) is
used to check the condition/expression
if(x==6) then the result of y is 1

Is This Answer Correct ?    3 Yes 0 No

What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;..

Answer / vijay r15

In c non zero values
in if statement r
considered to be true

here if(i=6)
so it makes if(6)
hence its true

op is 7

if 1ly execute false
for if(0)

got it
r
mail to
raj.Vijay55@gmail.Com

Is This Answer Correct ?    2 Yes 1 No

What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;..

Answer / suchita

this is logically wrong bcoz we use relational opr in
conditional statements. and thats why he displays last
statements.

Is This Answer Correct ?    4 Yes 8 No

What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;..

Answer / bhagya

1

Is This Answer Correct ?    1 Yes 5 No

Post New Answer

More C Interview Questions

Program to find the value of e raised to power x using while loop

5 Answers   IBM, N Tech,


How do I swap bytes?

0 Answers  


how to set Nth bit of variable by using MACRO

3 Answers   HCL,


can anyone proide me reading material on svit00ef27@yahoo.com please thanx in advance

1 Answers   IBM,


Which command is more efficient? *(ptr+1) or ptr[1]

3 Answers  






Can you define which header file to include at compile time?

0 Answers   Aspire, Infogain,


how the size of an integer is decided? - is it based on processor or compiler or OS?

19 Answers   HCL, JPR, Microsoft, nvidia,


how do you redirect stdout value from a program to a file?

1 Answers  


if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')

23 Answers  


write a programme to convert temperature from farenheit to celcius?

4 Answers   IBM,


List a few unconditional control statement in c.

0 Answers  


4)What would be the output? main() { int num=425; pf("%d",pf("%d",num)); } a)Comp error b)4425 c)4253 d)3435 e)none

10 Answers  


Categories