actually if else is a cndition checking system but the
switch is a selection of user typed type......
& secondly switch does not check all cases but jump directly
on the user interested case but if checkes all.............
I would like to answer this question from a compiler
perspective. When we have if else or if else tree, we have
many compare instructions ( assembly generated by compiler)
where as switch has only one compare and jump instruction.
If the idea is to does something after comparing the values,
it is always better to go with the switch case than if else
I would appreciate analyzing the assembly code, with the
same source, with if else tree and switch case statements.
expressions cannot be used as arguments in switsh, but in
if else any kind of exp can be used...
in the case of checkin a single variable for several values
SWITCH is the BEST.
in all other cases if else holds gud.
The switch branches on one value only, whereas the if-else
tests multiple logical expressions.
So you could say that the switch is a subset of if-else.
The potential difference if that switch is conceptually an
N-way branch point, whereas the if-else is always a
(repeated) binary branch.
However, if you are checking, say, a return code, against a
varied list of possibilities, then the switch can give
greater clarity to source code - and allow simpler addition
of new cases, making it easier for maintenance, as well as
allowing the compiler to generate simpler code.
Simpler code is possible because it can generate a jump
table to perform the multiple comparisons, i.e. in pseudo-code:
There are some things that you simply cannot do with a
switch. These are:
A float expression cannot be tested using a switch
Cases can never have variable expressions (for example it is
wrong to say case a +3 : )
Multiple cases cannot use same expressions.
write a c program for print your name .but,your name may be small
letter mean print a capital letter or your name may be capital
letter mean print a small letter .example
\\enter ur name :
The name is: SANKAR
enter your name:SAnkar
The name is:saNKAR
IS it possible to define a zero sized array in c.if it is
possible how can the elements of that array can be
accessed.array index starts from zero,if it is possible to
define zero sized array how can be its first element can be
What kind of sorting is this?
1.[Loop on I Index]
repeat thru step2 for i=1,2,........n-1
2.[For each pass,get small value]
repeat for j=i+1 to N do
3.[Sorted Values will be returned]