...
Programming-for-Output-Problems
October 6, 2023
Programming-for-Output-Problems
October 6, 2023
Programming-for-Output-Problems
October 6, 2023
Programming-for-Output-Problems
October 6, 2023

Programming-for-Output-Problems

Question 26
Consider the following program fragment
if(a > b)
if(b > c)
    s1;
else
   s2;
s2 will be executed if
A
a <= b
B
b > c
C
b >= c and a <= b
D
a > b and b <= c
Question 26 Explanation: 
Here, possibility to happen “dangling if” error. But according to else statement it is matched with above if statement only.
We can write code segment is like this because to avoid “dangling if”
if(a>b)
{
if(b>c)
{ s1; }
else
{ s2; }
}
→ To execute s2, it (a>b) should be TRUE. And it (b>c) should be FALSE.
Hence, Option-D is correct
Correct Answer: D
Question 26 Explanation: 
Here, possibility to happen “dangling if” error. But according to else statement it is matched with above if statement only.
We can write code segment is like this because to avoid “dangling if”
if(a>b)
{
if(b>c)
{ s1; }
else
{ s2; }
}
→ To execute s2, it (a>b) should be TRUE. And it (b>c) should be FALSE.
Hence, Option-D is correct
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!