challenge.h
#include <stdio.h>
float foo(float F);
float bar(float F);
main.c
#include "challenge.h"
float a = 6.8;
int main() {
float fa = foo(a);
float ba = bar(a);
printf(“%.1f\n”, fa + ba);
return 0;
}
challenge.c
#include "challenge.h"
extern float a;
float foo(float F) {
a = 2.6;
return F * a
}
challenge2.c
#include "challenge.h"
static float a;
float bar(float F) {
a = 5.2;
return foo(F) * a;
}
Given the source code above and we use "gcc main.c challenge.c challenge2.c -o challenge" to compile it. What's the output when we type ./challenge
The output is: 52.8
However, there are some mistakes in the code above that need to be fixed to compile that code without receiving an error.
First of all, the semicolon is missing in the end of return statement in challenge.c file. Secondly, it is better to replace double quotation marks (“ ”) in printf function in main.c file like this : printf("%.1f\n", fa + ba); (in order to avoid compile error).
Comments
Leave a comment