Discussion
Consider the following program fragment
if(a > b)
if(b > c)
s1;
else s2;
s2 will be executed if
Answer: D
Correct answer: a > b and b <= c
An else attaches to the nearest unmatched if, whatever the indentation suggests - the dangling-else rule. So the else here belongs to if (b > c), not to the outer one. Reaching it therefore needs the outer condition to be true, \(a > b\), and the inner one false, \(b \le c\). If \(a \le b\) nothing at all is executed.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development