what is the different between if-else and switch statment
(other than syntax)
Answers were Sorted based on User's Feedback
Answer / ailyn
Difference between switch - case and if - else is
we can't compare variables.
in the if - else, first the condition is verified,then it
comes to else whereas in the switch - case first it checks
the cases and then it switches to that particular case.
| Is This Answer Correct ? | 6 Yes | 1 No |
Though both are Braching statements,The selection of
statement is depending on developers.for simple
comparisions,there is no need to SWITCH statement.switch
statement will not use to compare floating,String and
logical expressions.
we can also use switch statement to somple
comparisons ,though it not fair as following segments :
switch(a>b)
{
case 0 :
max=a;
break;
case 1 :
max=b;
break;
}
I want to conclude that if...else structure is more
flexible and reliable than switch statement.
| Is This Answer Correct ? | 29 Yes | 25 No |
Answer / lingaraj patra
Th switch structure is a multiple-selection structure that
allows the handling of even more complicated decision
statements other than a two-way if-else structure
| Is This Answer Correct ? | 5 Yes | 3 No |
Answer / nilesh dinakr
In IF STATEMENT, we can build the logical conditin i.e.
usinf realtional operator but in SWITCH, we can use the
expression which yield int or char value but not float.
char value will be auoto typecast to int. shortly , switch
works only one int
| Is This Answer Correct ? | 4 Yes | 2 No |
Answer / sumeet
IF ELSE- First the condition is verified, then it comes to the else part.
SWITCH CASE- First it checks the cases and then it switches to that particular case.
IF ELSE- It implements like binary search.
SWITCH CASE-
It implements binary search.
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / chandra
in switch case we can tell the compiler that you can go
based on user choice
where as in if-else we can test the initial cond then we can
deside
| Is This Answer Correct ? | 3 Yes | 2 No |
Answer / sivanandareddy y
Switch Case is used when you want to check whether a
certain variable is equal to a set of particular values and
theres a different task to do for each value.If-then-else
is can be used to check for...
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / ahmed
in if else if one condition is satisfied then first
statement is execute else the 2nd statement.
While in switch their is multiple choice for selection
| Is This Answer Correct ? | 7 Yes | 7 No |
Answer / girish patidar
switch can't check all cases but goto directly
on the perticular case but if checkes all case and verify
condition then execute.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / abhay kumar
if else checks for all he conditions where as switch
directly jump to specified case.
| Is This Answer Correct ? | 0 Yes | 0 No |
Explain what are global variables and explain how do you declare them?
hi any body pls give me company name interview conduct "c" language only
What are formal parameters?
What is output redirection?
What is clrscr in c?
int array[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(array)/sizeof(int)) main() { if(-1<=SIZE) printf("1"); else printf("2"); }
progrem to generate the following series 1 12 123 1234 12345
why TCS selected more student in the software field from all institution.
In a switch statement, what will happen if a break statement is omitted?
Explain how do you search data in a data file using random access method?
#include<stdio.h> #include<conio.h> struct stu { int i; char j; }; union uni { int i; char j; }; void main() { int j,k; clrscr(); struct stu s; j=sizeof(s); printf("%d",j); union uni u; k=sizeof(u); printf("%d",k); getch(); } what is value of j and k.
given the piece of code int a[50]; int *pa; pa=a; to access the 6th element of the array which of the following is incorrect? a.*(a+5) b.a[5] c.pa[5] d.*(*pa + 5)