Answer
See explanation
Work Step by Step
Code generation is the process in which the high level source code is converted to the low level machine code by compiler in such a way that the original meaning and purpose of the code remains the same.
Code optimization is a part of code generation by which the code generation is optimized so that the machine can execute the code in fastest possible way, retaining the original meaning of the source code.