what is the different between if-else and switch statment
(other than syntax)

Answer Posted / sujith

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
tree.

I would appreciate analyzing the assembly code, with the
same source, with if else tree and switch case statements.

Is This Answer Correct ?    58 Yes 33 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you override a defined macro?

702


Can you assign a different address to an array tag?

702


plz let me know how to become a telecom protocol tester. thank you.

1742


What does %d do?

725


Differentiate between ordinary variable and pointer in c.

618






How do we open a binary file in Read/Write mode in C?

680


Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result

1469


In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.

2684


Is c weakly typed?

579


Whats s or c mean?

593


write a c program for swapping two strings using pointer

2094


An application package has been provided to you without any documents for the following application. The application needs to be tested. How will you proceed?

673


Explain what is the concatenation operator?

628


any "C" function by default returns an a) int value b) float value c) char value d) a & b

667


Explain what are the advantages and disadvantages of a heap?

597