printf() statements are a quick and easy way to trace the path of execution of a program.
But...
It can be tedious to insert and delete printf statements when code is being debugged. (After all, we don’t want debug statements flashing by all the time.)
Of course you can comment out(/* */) the printf() statements after code is debugged. But it can still be a bit tedious (yet, it’s my preferred method...).
There is another way however:
You can conditionally include debugging lines (such as printf() statements) by instructing the preprocessor to either include them or to not do so. Any line that starts with a hash mark (#) is meant for and interpreted by the preprocessor. In fact, we have already seen the preprocessor at work with our #include statements! Therefore, when using preprocessor directives to conditionally include debug statements then it is the preprocessor that does the work!
If you cannot see this codecast, please click here.
#if (condition)
#ifdef or #if defined
#elif (condition)
#else (branch statement for preprocessor!)
#endif
Check Your UnderstandingCheck Your Understanding
1.
What is the output of the following code, once it has been compiled and run: