+ 1

Switch statement in c++/java: "case values"

why in c/c++ and java case values should be compile-time constant?! and what's difference between multiple if and switch statement at speed of program? i didn't see any notable difference(with multiple if statement) in generated assembly code!

3rd Oct 2021, 7:39 PM
Mehran
Mehran - avatar
7 Answers
+ 2
Martin Taylor ok. i see. thanks.
3rd Oct 2021, 9:25 PM
Mehran
Mehran - avatar
+ 1
Martin Taylor Yeah. actually i meant multiple if-else. thank you.
3rd Oct 2021, 8:23 PM
Mehran
Mehran - avatar
+ 1
Martin Taylor i know compiler resolve sizeof(staticarray) at compile time. but How does the program remember the length of the dinamic array? delete[] arr; i think it needs to know how many bytes are allocated. (to free them)
3rd Oct 2021, 10:44 PM
Mehran
Mehran - avatar
+ 1
Martin Taylor oh I thought there's no runtime management in c++. thanks.
4th Oct 2021, 11:47 AM
Mehran
Mehran - avatar