Because memory will be allocated for int b
but when the application is run "b = 20
" will never be evaluated.
This is because your switch
-statement will jump down to either case 1:
1 or default:
, skipping the statement in question - thus b
will be uninitialized and undefined behavior is invoked.
The following two questions (with their accepted answers) will be of even further aid in your quest searching for answers:
Turning your compiler warnings/errors to a higher level will hopefully provide you with this information when trying to compile your source.
Below is what gcc
says about the matter;
foo.cpp:6:10: error: jump to case label [-fpermissive]
foo.cpp:5:9: error: crosses initialization of 'int b'
1 since int a
will always be 1 (one) it will always jump here.
2 most relevant out of the two links, answered by me.