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.
1 and 2
2 and 3
1, 2 and 4
2, 3, 4
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
25 comments Page 2 of 3.

Ummul said:   10 years ago
Option D is correct. Since there are some if statements which do not have any else part and they cannot be converted into ?: So 3 conditions are fulfilled but first condition is not fulfilled.

Sudheer s said:   1 decade ago
Friends here only only if - else can be replaced by ternary operator but not more than one it is wrong so there he specified more than one if-else.

Shalin said:   8 years ago
return x>y?1:0;

It will work.

I think question is misprinted, first one is correct

Tell me a single example which cannot be converted.
(1)

Gayatri Walmik said:   9 years ago
We can use ?: for nested if else statements too. Like if (x>5? (x>10?x=1:x=2) :x=3).

What does it mean by multiple if else statements?

Vimal Dahduk said:   1 decade ago
@Madhu.

You are right for this case but many case like (return X) in if condition so ?: is not allowed if condition only.

Hemanth kumar.v said:   7 years ago
Actually, ?: this indicates that conditional operator,we use this ?: as an alternative for if-else functions limitedly.
(1)

Arun Kumar said:   1 decade ago
Can we multiple else statements?

If so which else statement will be executed in case failure of if statement?

Noel said:   7 years ago
I disagree with the answer because one can write nested ternary operators equating nested if else statements.
(1)

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..:)

Pawan kumar saini said:   9 years ago
We can't use return statements in ?: whereas we can use it in if else blocks.
So option D is true.


Post your comments here:

Your comments will be displayed after verification.