Question
Download Solution PDFThe ternary operator can be used as a replacement for which loop/statement?
Answer (Detailed Solution Below)
Detailed Solution
Download Solution PDFThe correct answer is: 1) If-else statement
Explanation:
The ternary operator (condition ? expr1: expr2) is a shorthand for a simple if-else statement. It evaluates a condition and returns one of two expressions based on whether the condition is true or false.
Option Analysis
- For loop → The ternary operator cannot replace iterative loops (it lacks repetition logic).
- While loop → Same as above; loops require repeated execution, which the ternary operator cannot do.
- Switch-case statement → The ternary operator handles binary (true/false) conditions, not multi-way branching.
Example:
C Programming
/ Using if-else:
if (x > 10) {
y = 100;
} else {
y = 0;
}
/ Equivalent ternary:
y = (x > 10) ? 100 : 0;
Last updated on Jun 7, 2025
-> RRB JE CBT 2 answer key 2025 for June 4 exam has been released at the official website.
-> Check Your Marks via RRB JE CBT 2 Rank Calculator 2025
-> RRB JE CBT 2 admit card 2025 has been released.
-> RRB JE CBT 2 city intimation slip 2025 for June 4 exam has been released at the official website.
-> RRB JE CBT 2 Cancelled Shift Exam 2025 will be conducted on June 4, 2025 in offline mode.
-> RRB JE CBT 2 Exam Analysis 2025 is Out, Candidates analysis their exam according to Shift 1 and 2 Questions and Answers.
-> The RRB JE Notification 2024 was released for 7951 vacancies for various posts of Junior Engineer, Depot Material Superintendent, Chemical & Metallurgical Assistant, Chemical Supervisor (Research) and Metallurgical Supervisor (Research).
-> The selection process includes CBT 1, CBT 2, and Document Verification & Medical Test.
-> The candidates who will be selected will get an approximate salary range between Rs. 13,500 to Rs. 38,425.
-> Attempt RRB JE Free Current Affairs Mock Test here
-> Enhance your preparation with the RRB JE Previous Year Papers.