C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers


10,705 users

What are header files? Are functions declared or defined in header files in C ?

0 votes
asked Jan 8, 2014 by sara Guru (24,570 points)

1 Answer

0 votes
Functions and macros are declared in header files. Header files would be included in source files by the compiler at the time of compilation. Header files are included in source code using #include directive. #include<some.h> includes all the declarations present in the header file 'some.h'. A header file may contain declarations of sub-routines, functions, macros and also variables which we may want to use in our program. Header files help in reduction of repetitive code.

Syntax of include directive:

#include<stdio.h> //includes the header file stdio.h, standard input output header into the source code Functions can be declared as well as defined in header files. But it is recommended only to declare functions and not to define in the header files. When we include a header file in our program we actually are  including all the functions, macros and variables declared in it. In case of pre-defined C standard library header files ex(stdio.h), the functions calls are replaced by  equivalent binary code present in the pre-compiled libraries. Code for C standard functions are linked and then  the program is executed. Header files with custom names can also be created.

Program: Custom header files example


Index: restaurant.h


int billAll(int food_cost, int tax, int tip);


Index: restaurant.c



int billAll(int food_cost, int tax, int tip) {

int result;

result = food_cost + tax + tip;

printf("Total bill is %d\n",result);

return result;



Index: main.c




int main() {

int food_cost, tax, tip;

food_cost = 50;

tax = 10;

tip = 5;


return 0;

answered Jan 8, 2014 by rajesh Guru (39,140 points)

Related questions

0 votes
2 answers 4,054 views
0 votes
1 answer 1,433 views
1,433 views asked Jan 8, 2014 by keem Expert (13,240 points)
0 votes
1 answer 1,364 views
1,364 views asked Jan 8, 2014 by keem Expert (13,240 points)
0 votes
1 answer 36 views
0 votes
1 answer 4,206 views