Computer Science, asked by aniruddhatito, 1 year ago

What is the differences between if-else, switch case and ternary operator ?

Answers

Answered by Sarthak701
0
difference b/w these are
Following are some difference between if else and conditional operator –

BasisConditional Operator(? : )If-elseProvides Concise and clean codeNoYesProvides compact codeYesNoFlexibleNoYesCompound statement or single statementUsed for single expressionUsed for single as well as compound statement and expression.Expression or statementThe (?:) produces an expression and returns a value.If then else is a statement.
If can have multiple statements, multiple assignments and expression it its bodyComplexityVery complex when using in nested form and so, difficult to understand it.Not very much ComplexReplacement of codeEvery conditional operator can be replaced with if-else codebut every if else code can’t be replaced with if else as if else can have multiple statements.

Similar questions