Discussion
Which of the following statements are correct about an if-else statements in a C-program?
1. Every if-else statement can be replaced by an equivalent statements using ?: operators
2. Nested if-else statements are allowed.
3. Multiple statements in an if block are allowed.
4. Multiple statements in an else block are allowed.
Answer: D
Correct answer: 2, 3, 4
2, 3 and 4 are true: if-else statements nest freely, and either branch may hold as many statements as you like inside braces.
1 is false. The conditional operator ?: combines expressions, not statements, so it cannot replace an if-else whose branches contain declarations, loops, or several statements. It replaces only the special case where both branches produce a value.
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