Computer Science, asked by geekyboy134, 1 year ago

What would be the value of x after the following
code segment compltes execution ?
intx=0;
if (x >=0)
x += 5;
if(x>=5)
X+= 2;
(A) 7
(B) 5
(C) O
(D) 2​

Answers

Answered by tennysonshivam1234
1

Answer: Sorry, but no Output.

Explanation: There's no Statement in the Code for Displaying the Output.

Rather, if the statement for displaying the output is at the last, then the output will be 7.

Hope it Helped all...Please rectify the Code...:-)

Answered by anshulsoni41
1

it will have no output but if there is a print statement then answer would be x,=7


geekyboy134: The answer is correct but can you please tell me in brief
geekyboy134: how did you do that
tennysonshivam1234: According to First statement, initially, x=0.
geekyboy134: And ?
tennysonshivam1234: According to second statement, the value of x is verified as being >= 0. So, after the execution of third statement (which can also be written as x=x+5), value of x will be modified as 5. Now, after the execution of fourth statement, the value of x is verified as being >= 5, so after the execution of fifth statement(what ch can also be written as x=x+2), the value of x is modified as 7. And that's it... Hope it Helped...:-)
Similar questions