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

What is a scope resolution operator in c?

0 Answers  


How can I implement a delay, or time a users response, with sub-second resolution?

0 Answers  


AMMONG THE 4 STROAGE CLASSES IN C, WHICH ONE FASTEST?

13 Answers   HCL,


write an algorithm and c program to add two 2x2 matrics

2 Answers  


How can I delete a file?

0 Answers  






how to find the kth smallest element in the given list of array elemnts.

8 Answers   Silicon,


At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with these names could be kept in that shelf as in this example: bottom of shelf ---> [AAAJKRDFDEWAAYFYYKK]-----Top of shelf. All these packets are to be loaded on cars. The cars are lined in order, so that the packet could be loaded on them. The cars are also named [A, B, C, D, E,………….]. Each Car will load the packet with the same alphabet. So, for example, car ‘A’ will load all the packets with name ‘A’. Each particular car will come at the loading point only once. The cars will come at the loading point in alphabetical order. So, car ‘B’ will come and take all the packets with name ‘B’ from the shelf, then car ‘C’ will come. No matter how deep in the shelf any packet ‘B’ is, all of the ‘B’ packets will be displaced before the ‘C’ car arrives. For that purpose, some additional shelves are provided. The packets which are after the packet B, are kept in those shelves. Any one of these shelves contains only packets, having the same name. For example, if any particular shelf is used and if a packet with name X is in it, then only the packets having names X will be kept in it. That shelf will look like [XXXXXXX]. If any shelf is used once, then it could be used again only if it is vacant. Packets from the initial shelf could be unloaded from top only. Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

0 Answers   Infosys,


how to print value of e(exp1)up to required no of digits after decimal?

1 Answers  


Write a program to print distinct words in an input along with their count in input in decreasing order of their count..

1 Answers  


How can you draw circles in C?

0 Answers   Accenture,


what is c programing

11 Answers   Wipro,


if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.

1 Answers   TCS,


Categories