C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - Point Out Correct Statements (Q.No. 4)
4.
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. |
Discussion:
25 comments Page 3 of 3.
Raju royal said:
1 decade ago
Conditional operator can be used for multiple if-else statements..
ex:
using if-else:-
if(x!=40)
if(x<40)
salary=4*x+100;
else
salary=4.5*x+150;
else
salary=300;
Using conditional operator:-
salary=(x!=40)?((x<40)?(4*x+100):(4.5*x+150)):300;
ex:
using if-else:-
if(x!=40)
if(x<40)
salary=4*x+100;
else
salary=4.5*x+150;
else
salary=300;
Using conditional operator:-
salary=(x!=40)?((x<40)?(4*x+100):(4.5*x+150)):300;
Gayathri.M said:
1 decade ago
'?:' can be used instead of single if else statement and you can't use it in multiple if else statements..:)
Sindhu said:
1 decade ago
We can replace an if-else structure with a ternary operator. Isn't it so?
Sridhar said:
1 decade ago
Simple in under one if statement we can declare many if and else satements.
Vijaykumar b said:
1 decade ago
Option 3. Multiple statements in an if block are allowed - is also correct, because we can execute multiple statements against true value of if (condition) by placing the statements within { and }.
So all the options are correct.
So all the options are correct.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers