Which of the following statements about the Answer program BEST describes the control flow anomalies to be found in the program?

Consider the pseudo code for the Answer program:

Which of the following statements about the Answer program BEST describes the control flow anomalies to be found in the program?
A . The Answer program contains no control flow anomalies.
B . The Answer program contains unreachable code.
C . The Answer program contains unreachable code and an infinite loop.
D . The Answer program contains an infinite loop.

Answer: C

Explanation:

The provided pseudo code for the Answer program shows a WHILE loop that will always execute because the condition for the loop to terminate (a >= d) is never met within the loop’s body. This results in an infinite loop. Additionally, since the value of ‘b’ is initialized with ‘a + 10’ and ‘a’ starts from a value that is read and then set to 2, ‘b’ will never be equal to 12. Therefore, the ‘THEN’ branch of the IF statement, which includes ‘print(b)’, is unreachable. These are control flow anomalies because they represent logic in the code that will not function as presumably intended.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments