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 1 of 3.

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

Panchangam Chidrupi said:   5 years ago
What is the difference between = and == operators? Please tell me.

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

Vrushabh said:   6 years ago
I think all four options are correct. because we can replace every if-else with ?: even nested ones also.

eg. if(a==5){
if(b==5){
printf("%d",b);
}
else{
printf("%d",b+1);
}
}
else{
printf("%d',a);
}


It can be replaced by.
(a==5)?(b==5?printf("%d",b):printf("%d",b+1)):printf("%d',a);
(2)

Shalin said:   6 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.

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

Gayatri Walmik said:   7 years ago
Can anyone please explain why the first option is incorrect?

Gayatri Walmik said:   7 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?

Nehal said:   7 years ago
One more thing that we cannot use return in conditional statement.

Ummul said:   7 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.


Post your comments here:

Your comments will be displayed after verification.