What is the difference between if else and switchstatement



What is the difference between if else and switchstatement..

Answer / Surya Pratap Singh

In the programming language C, both if-else statements and switch statements are used for making decisions based on conditions. However, they differ in their syntax and the number of conditions they can handle. An if-else statement is used to test one condition at a time, and it can include multiple nested if-else statements for handling more complex conditional logic. A switch statement allows for testing multiple conditions using a single statement, and it can be more efficient when dealing with many similar cases. Each case in a switch statement corresponds to a specific value or range of values, and the program execution jumps directly to the corresponding code block when the switch expression matches one of the cases.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

In scanf h is used for

4 Answers   BFL,


write a program to display the frequency of each element in a given array in c language

1 Answers  


What is that continue statement??

4 Answers  


The operation of a stair case switch best explains the a) or operation b) and operation c)exclusive nor operation d)exclusive or operation Which of the following is/are syntactically correct? a) for(); b) for(;); c) for(,); d) for(;;);

1 Answers   HCL, Public Service Commission,


What is this pointer in c plus plus?

1 Answers  


main() { int a[10]; printf("%d",*a+1-*a+3); }

2 Answers  


what is use of loop?

10 Answers   Infosys,


Is fortran still used today?

1 Answers  


Explain what are linked list?

1 Answers  


What are terms in math?

1 Answers  


What is the difference between ‘g’ and “g” in C?

2 Answers  


How can you read a directory in a C program?

1 Answers  


Categories