:: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Categories >> Software >> Programming Languages >> C


 C interview questions  C Interview Questions (2262)
 C++ interview questions  C++ Interview Questions (1118)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (647)
what is the different between if-else and switch statment
(other than syntax)
 Question Submitted By :: C
I also faced this Question!!     Answer Posted By  
# 1
Simply saying, IF-ELSE can have values based on constraints
where SWITCH can have values based on user choice.
Is This Answer Correct ?    149 Yes 32 No
# 2
The main 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 ?    134 Yes 29 No
Fazlur Rahaman Naik
# 3
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.............
Is This Answer Correct ?    42 Yes 14 No
Kuldeep Sadhu
# 4
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.
Is This Answer Correct ?    49 Yes 28 No
# 5
switch has its own pros and cons,

Favours coding style.
From performance point, switch case creates table. It
directly jumps to the required location based on table

If-else is hard for code-walk
Optimised (please check).
Is This Answer Correct ?    35 Yes 17 No
Ananth Kumar
# 6
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
in all other cases if else holds gud.
Is This Answer Correct ?    30 Yes 18 No
# 7
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:

DEFW case1_address
DEFW case1_value
DEFW caseN_address
DEFW caseN_value
DEFW NULL /* terminator */

- search _jump_table for case_value
- branch to corresponding case_address, or take default
action if NULL terminator found instead.

In the special case that case1 ... caseN values are
sequential numbers (maybe with a few gaps) then the table
and code can be further simplified as a simple indexed branch:

DEFW case1_address
DEFW default_address /* fill in any holes !*/
DEFW caseN_address

- check value is between case1_value and caseN_value
- subtract case1_value
- load branch address word from _jump_table word-indexed on
previous result
Is This Answer Correct ?    21 Yes 11 No
# 8
we depand the condition
if condition true then true block will be excuted
false block will be excuted
switch have number of choice we can excute any choice
Is This Answer Correct ?    13 Yes 5 No
Sanjay Parmar Sirsa
# 9
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.
Is This Answer Correct ?    11 Yes 3 No
# 10
we can use all varriables within if else.but we can't use
all verriables within switch case.example :-float and
String we can't use within switch case.
Is This Answer Correct ?    12 Yes 4 No
Sujoy Dutta

Other C Interview Questions
  Question Asked @ Answers
Identify the correct argument for the function call fflush () in ANSI C: A)stdout B)stdin C)stderr D)All the above Accenture 5
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 : sankar The name is: SANKAR (or) enter your name:SAnkar The name is:saNKAR IBM 3
main() { float a=3.2e40; printf("%d",a); } Satyam 9
write a program to display the numbers in the following format 4 4 3 3 3 3 2 2 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 4 IBM 4
what is output of the following statetment?Printf(%x, -1<<4); ?   5
Which of the Following is not defined in string.h? A)strspn() B)strerror() C)memchr() D)strod() Accenture 2
write a program that will read the temperature in Celsius and convert that into Fahrenheit.   1
program to print circle structure   1
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 accesseed. TCS 5
without using control structures and control structures find the max and min of given 2 nos HCL 1
What kind of sorting is this? SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort Accenture 3
For more C Interview Questions Click Here 

Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
Copyright 2013  All Rights Reserved.   ::