types/prog-with-types.c - Et C program med typer - og med forskellige udfordringer. | Lektion 8 - slide 2 : 29 Program 1 |
#include <stdlib.h> #include <stdio.h> double f (double p1, int p2){ return p1 + p2; // Type of p2 is converted. } int main(void){ int i = 1, j = 5; double d = 2.5, e = 2.4; printf("The first result is %f\n", f(d, i)); // Types are OK. printf("The second result is %f\n", f(i+j, d-e)); // Types are converted. printf("The third result is %d\n", f(d-e, 0)); // Type error in the // the executing program: // Printing expected: 0.1 // Wrong result. return 0; }