|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
if vs. switch memory
Lets say the user is given 1-10 options to be taken to a function (each number going to a different function). To see what the user typed in, would it be more efficient to use if statements or a switch to redirect them? It won't make a huge deal in this situation, but lets say the program was huge, which one would be the better call? Thanks.
-andy
__________________
hmmm... |
|
#2
|
||||
|
||||
|
In this case I would suggest using switch
|
|
#3
|
|||
|
|||
|
Of course a third option is having an array of function pointers and dereferencing an index based on the user's choice (after bounds checking, of course). This can handle huge ranges of possibilities in a few lines of code.
Not sure which method is fastest, but the case structure is definitely the easiest to read... |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > if vs. switch memory |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|