
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

runner$ cat -n example0.c 1 /* Volume of a sphere of radius r / 2 #include <stdio.h> 3 #define pi 3.14159265358979; 4 int main() 5 { 6 double r, vol; 7 / input the radius r / 8 scanf("%lf", r); 9 / calculate the volume / 10 vol = (4/3)pirrr; 11 / print radius and volume */ 12 printf("Radius:%10.6f, Volume:%10.6f\n", r, vol); 13 return 0; 14 } runner$ lint -m -u example0.c (8) warning: variable may be used before set: r (10) error: cannot dereference non-pointer type
statement has null effect (10) lint: errors in example0.c; no output created lint: pass2 not run - errors in example0.c runner$ cat -n example1.c 1 /* Volume of a sphere of radius r / 2 #include <stdio.h> /***************************/ 3 #define pi 3.14159265358979 / NOTE: SEMICOLON DELETED / 4 int main() /***************************/ 5 { 6 double r, vol; 7 / input the radius r / /********************/ 8 scanf("%lf", &r); / NOTE: & INSERTED / 9 / calculate the volume / /********************/ 10 vol = (4/3)pirrr; 11 / print radius and volume / 12 printf("Radius:%10.6f, Volume:%10.6f\n", r, vol); 13 return 0; 14 } runner$ lint -m -u example1.c function returns value which is always ignored printf scanf runner$ cc -o example1 example1.c runner$ example 1. Radius: 1.000000, Volume: 3.141593 (NOTE: WRONG ANSWER!) runner$ cat example2.c / Volume of a sphere of radius r */ #include <stdio.h> #define pi 3.
int main() { double r, vol; /* input the radius r / scanf("%lf", &r); / calculate the volume / /******************************/ vol = (4.0/3.0)pirrr; / NOTE: (4/3) NOW (4.0/3.0) / / print radius and volume */ /******************************/ printf("Radius:%10.6f, Volume:%10.6f\n", r, vol); return 0; } runner$ example 1. Radius: 1.000000, Volume: 4. runner$ example 10. Radius: 10.000000, Volume:4188.