recategorized by
3,904 views
21 votes
21 votes

In the following Pascal program segment, what is the value of X after the execution of the program segment?

X := -10; Y := 20;
If X > Y then if X < 0 then X := abs(X) else X := 2*X;
  1. $10$
  2. $-20$
  3. $-10$
  4. None
recategorized by

1 Answer

Best answer
32 votes
32 votes

The answer of $X$ remains unchanged. As the if condition becomes false.

X := -10

The answer is C . This is a classic example of an $\text{if-else}$ issue. Always $else$ matches for nesting to the closest $\text{if}$ in C Programming & Pascal .
https://en.wikipedia.org/wiki/Dangling_else

if (x>y)
{
   if (x<0)
       x=abs(x)
    else
       x=2*x
}
edited by
Answer:

Related questions

11 votes
11 votes
3 answers
2
21 votes
21 votes
2 answers
4
Kathleen asked Oct 8, 2014
4,953 views
Merge sort uses:Divide and conquer strategyBacktracking approachHeuristic searchGreedy approach