If I define a function in file func1.c
, and I want to call it from file call.c
. How can I accomplish this task?
You must declare int add(int a, int b); (note to the semicolon) in a header file and include the file into both files. Including it into Main. c will tell compiler how the function should be called.
The main function always acts as a driver function and calls other functions. We can also write function call as a parameter to function. In the below code, first add(num1, num2) is evaluated, let the result of this be r1. The add(r1, num3) is evaluated.
You would put a declaration for the function in the file func1.h
, and add #include "func1.h"
in call.c
. Then you would compile or link func1.c
and call.c
together (details depend on which C system).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With