Task B: Finding Errors in a Simple Program
As compiler warnings are an essential aid when programming in C and C++, to demonstrate this, the program below contains a subtle error:
#include <stdio.h>
int main(void)
{
printf("Two plus two is %f\n", 4.0);
return 0;
}
This warning is not obvious at first sight but can be detected by the compiler if the warning option -Wall has been enabled.
6. Compiling the program above, 'warning.c', with the warning option -Wall included, what message is produced by the compiler? – Please include your output here.
Ans:
7. What does the warning message indicate?
Ans:
8. In order to fix this warning, what needs to be corrected in the source code?
Ans:
9. Without the warning option -Wall, the program appears to compile cleanly, but produces incorrect results. Please include what output was printed?
Ans: