In computer programming, redundant code is source code or compiled code that is unnecessary. Code that can be removed without affecting its desired behavior is redundant.
Notable categories of redundant code include:
In the following C code, the second <code>x * 2</code> expression is redundant code. Line 2 can be removed, or alternatively, line 3 can be changed to .
A more subtle example involves the C preprocessor that inserts code before compilation. Consider:
After preprocessing, the code expands to code that evaluates both and twice. To eliminate the duplicate code, the macro could be converted to a function.