> I don't know how they'll end up on assembly after compiled.
Just do
gcc -S prog.c and find out by examining
prog.s
Other compilers will have similar options.
> How does switch really work?
Like a chain of if / else if.
With some tweaks if there is no break statement at the end of a case.
A jump table is a possible implementation, but it's not the only one.
The standard only describes a behaviour.
> I heard a rumor that compiler makes other elements happen so it
> can find things faster, so it would be linear.
Well that really depends on the compiler.
There are all sorts of factors that might alter what gets generated.
- the machine architecture you're compiling for.
- what optimisation level.
- whether you're optimising for speed or memory space.
- whether you have run-time profile information about which cases are most likely.
Old, but still informative.
http://www.jauu.net/2010/06/15/gcc-generated-switch-jump-tables/