Testing and Debugging
Diagnostic Log
A debug flag can print the values that explain how a result was produced.
Diagnostic Log
diagnostic_log.c
#include <stdio.h>
int main(void) {
int debug = ;
int width = 6;
int height = 4;
int area = width * height;
if (debug) {
printf("debug width=%d height=%d\n", width, height);
}
printf("area=%d\n", area);
return 0;
}
#include <stdio.h>
int main(void) {
int debug = ;
int width = 6;
int height = 4;
int area = width * height;
if (debug) {
printf("debug width=%d height=%d\n", width, height);
}
printf("area=%d\n", area);
return 0;
}
debug flag
A flag lets diagnostic output be turned on while leaving the normal result unchanged.
trace value
Printing intermediate values can confirm which path the program followed.