Linking source files by forward declaring without using headers

Viewed 56

Goal is to write a program that consists of two source-files. The first (Main.c) contains the main() function and gives the variable i a value. The second source-file (Print.c) multiplies i by 2 and prints it. Print.c contains the function print() which can be called from main(). The output prints a huge number not even divisible by the assigned integer. How do I fix this?

My main.c

#include <stdio.h>

int i;
void print();

int main()
{
    int i = 10;
    print();
    return 0;
}

My print.c:

#include <stdio.h>

void print(int i)
{
    printf("%d", 2 * i);
}
0 Answers
Related