Continental Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
The optimization should happen during compile time, with respect to the above chunk of code.
This is because
1) Other than " abc = 3 " the code is not being altered anywhere
2) Also you don't see any statement like " abc = RHS " where you are trying to assign a new value at run time.
Hece the compiler is very sure that " Else " part never gets executed. Hence code optimization should happen @ compile time.
It says 'abc' is a global variable, which could be externed in other file and modified over there??
so i don't think compiler can optimize this particular case..
plz correct if wrong..
correct. In this case compiler is not sure if the variable is mopdified in any other translation unit.
You're definitely correct that in C or C++ code, the optimization will be done at compile time if it is done at all. In your particular situation, the compiler definitely could decide to perform the optimization.
- eugene.yarovoi February 04, 2012