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.
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.
It will work.
I think question is misprinted, first one is correct
Tell me a single example which cannot be converted.
(1)
Vrushabh said:
8 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);
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);
(4)
Noel said:
7 years ago
I disagree with the answer because one can write nested ternary operators equating nested if else statements.
(1)
Panchangam Chidrupi said:
7 years ago
What is the difference between = and == operators? Please tell me.
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)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers