C Header Files

Header file is important part of c programming. Because they provide group of functionality. When you'll are including predefined header file in a source code. Then this header file functions are available and accessible inside this source code. C Programming language are provides various predefined header files. This header files are included by preprocessor directive.

Including header file syntax

//predefined header files
#include <file_name>

//user defined header file
#include <path_and_file_name>

<file_name> are indicates to that is inbuilt header file. Extension of header file is (.h) .header file are two type

Header File Type

Perdefined Header File

That is inbuilt header files of C programming language that are include when we are installed C compiler. Here given standard header file in c programming.

<math.h> <stdio.h> <time.h> <string.h>
<assert.h> <ctype.h> <errno.h> <limits.h>
<float.h> <locale.h> <stddef.h> <setjmp.h>
<stdarg.h> <signal.h> <stdlib.h>


This header file support various math functions. This header file include various math functions. look at view following functions.

Method Syntax
sin() double sin(double);
cos() double cos(double);
tan() double tan(double);
sinh() double sinh(double);
cosh() double cosh(double);
tanh() double tanh(double);
asin() double asin(double);
acos() double acos(double);
atan() double atan(double);
atan2() double atan2(double, double);
exp() double exp(double);
log() double log(double);
log10() double log10(double);
pow() double pow(double, double);
sqrt() double sqrt(double);
ceil() double ceil(double);
floor() double floor(double);
fabs() double fabs(double);
ldexp() double ldexp(double, int);
frexp() double frexp(double, int*);
modf() double modf(double, double*);
fmod() double fmod(double, double);


this function are calculate square root. square function are accept one parameter. parameter value are in form of double. we can also pass integer value.and there function are return one double value.


double sqrt(double var);

For example

 Example math.h sqrt function.
#include <stdio.h>
#include <math.h>

int main(){
  //print square root of 16
  printf("square root of [%d] is : %lf\n",16,sqrt(16));
  printf("square root of [%lf] is : %lf\n",49.4,sqrt(49.4));


square root of [16] is : 4.000000
square root of [49.400000] is : 7.028513


This function are calculate power of two number. first is base let say assume that this is (a). and second one is b. then this function are calculate (a^b).


 /*return double value
  accept double value*/
  double pow(double a, double b);

For example

 Example math.h pow function.
#include <stdio.h>
#include <math.h>

int main(){
  printf("%d ^ %d : %lf\n",3,3,pow(3,3));
  printf("%lf ^ %d: %lf\n",4.3,3,pow(4.3,3));


3 ^ 3 : 27.000000
4.300000 ^ 3: 79.507000


return ceil value. this value are greater than or equal to x.


double ceil(double x);
 Example math.h ceil function.
#include <stdio.h>
#include <math.h>

int main(){




 Example math.h floor function.
#include <stdio.h>
#include <math.h>

int main(){




 Example math.h fabs function.
#include <stdio.h>
#include <math.h>

int main(){
  printf("%lf\n",fabs(-120.5)); //nagative value




 Example math.h cos function.
#include <stdio.h>
#include <math.h>
int main(){
  printf("cos(4)  : %lf\n",cos(4));
  printf("cos(45) : %lf\n",cos(45));


cos(4)  : -0.653644
cos(45) : 0.525322


 Example math.h sin function.
#include <stdio.h>
#include <math.h>
int main(){
  printf("sin(90)  : %lf\n",sin(90));
  printf("sin(145) : %lf\n",sin(145));


sin(90)  : 0.893997
sin(145) : 0.467745


 Example math.h log10 function.
#include <stdio.h>
#include <math.h>
int main(){
  printf("log10(90)  : %lf\n",log10(90));
  printf("log10(147) : %lf\n",log10(147));


log10(90)  : 1.954243
log10(147) : 2.167317


Method Syntax
fopen() FILE* fopen(const char*, const char*)
freopen() FILE* freopen(const char*, const char*, FILE*);
fflush() int fflush(FILE*);
fclose() int fclose (FILE*);
remove() int remove(const char*);
rename() int rename(const char*, const char*);
tmpfile() FILE* tmpfile(void);
tmpnam() char* tmpnam(char*);
setvbuf() int setvbuf(FILE*, char*, int, size_t)
setbuf() void setbuf(FILE*, char*)
fprintf() int fprintf(FILE*, const char*, ...);
printf() int printf(const char*, ...);
sprintf() int sprintf(char*, const char*, ...);
_snprintf() int _snprintf(char*, size_t, const char*, ...);
vfprintf() int vfprintf(FILE*, const char*, __VALIST);
vprintf() int vprintf(const char*, __VALIST);
vsprintf() int vsprintf(char*, const char*, __VALIST);
_vsnprintf() int _vsnprintf (char*, size_t, const char*, __VALIST);
vscanf() int vscanf(const char * , __VALIST);
scanf() int scanf(FILE * , const char * ,__VALIST);
vsscanf() int vsscanf(const char * ,const char * , __VALIST);
fscanf() int fscanf (FILE*, const char*, ...);
scanf() int scanf(const char*, ...);
sscanf() int sscanf(const char*, const char*, ...);
fgetc() int fgetc(FILE*);
fgets() char* fgets(char*, int, FILE*);
fputc() int fputc(int, FILE*);
fputs() int fputs(const char*, FILE*);
gets() char* gets(char*);
puts() int puts(const char*);
ungetc() int ungetc(int, FILE*);
_filbuf() int _filbuf(FILE*);
_flsbuf() int _flsbuf (int, FILE*);
getc() int getc(FILE* )
putc() int putc(int , FILE* )
getchar() int getchar(void)
putchar() int putchar(int )
getc() int getc(FILE*);
putc() int putc(int, FILE*);
getchar() int getchar(void);
putchar() int putchar(int);
fread() size_t fread(void*, size_t, size_t, FILE*);
fwrite() size_t fwrite(const void*, size_t, size_t, FILE*);
fseek() int fseek(FILE*, long, int);
ftell() long ftell(FILE*);
rewind() void rewind(FILE*);
seek() int seek(FILE *, long, int);
write() int write(const void*, size_t, size_t, FILE*);
fgetpos() int fgetpos(FILE*, fpos_t*);
fsetpos() int fsetpos(FILE*, const fpos_t*);
feof() int feof(FILE*);
ferror() int ferror(FILE*);
clearerr() void clearerr(FILE*);
perror() void perror(const char*);
_popen() FILE* _popen(const char*, const char*);
_pclose() int _pclose(FILE*);
_flushall() int _flushall(void);
getchar() int getchar(void);
putchar() int putchar(int);
dopen() FILE* dopen(int, const char*);
_fileno() int _fileno(FILE*);
closeall() int closeall(void);

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment

© 2021, kalkicode.com, All rights reserved