Home Interview Questions and AnswersTechnical Interview Questions and AnswersC Programming C Language Library Functions Interview Questions and Answers For Freshers Part-1

library function1. Why should I use standard library functions instead of writing my own?

The standard library functions have three advantages: they work, they’re efficient, and they’re portable. They work: Your compiler vendor probably got them right. More important, the vendor is likely to have done a thorough test to prove they’re right, more thorough than you C Language Library Functions Interview Questions and Answers For Freshers Part-1probably have time for. (There are expensive test suites to make that job easier.)

They’re efficient: Good C programmers use the standard library functions a lot, and good compiler vendors know that. There’s a competitive advantage for the vendor to provide a good implementation. When competing compilers are compared for efficiency, a good compiler implementation can make all the difference. The vendor has more motivation than you do, and probably more time, to produce a fast implementation.

2. What header files do I need in order to define the standard library functions I use?

The funny thing is, these are not necessarily the files that define what you’re looking for. Your compiler guarantees that (for example) if you want the EDOM macro, you can get it by including <errno.h>. EDOM might be defined in <errno.h>, or <errno.h> might just include something that defines it. Worse, the next version of your compiler might define EDOM somewhere else.

A few names are defined in multiple files: NULL, size_t, and wchar_t. If you need a definition for one of these names, use a file you need to include anyway, or pick one arbitrarily. (<stddef.h> is a reasonable choice; it’s small, and it defines common macros and types.)

Standard library functions header files.
Function/Macro           Header File
abort     –     stdlib.h
abs     –     stdlib.h
acos     –     math.h
asctime     –     time.h
asin     –     math.h
assert     –     assert.h
atan     –     math.h
atan2     –     math.h
atexit     –     stdlib.h
atof     –     stdlib.h
atoi     –     stdlib.h
atol     –     stdlib.h
bsearch     –     stdlib.h
BUFSIZ     –     stdlib.h
calloc     –     stdlib.h
ceil     –     math.h
clearerr     –     stdio.h
clock     –     time.h
CLOCKS_PER_SEC     –     time.h
clock_t     –     time.h
cos     –     math.h
cosh     –     math.h
ctime     –     time.h
difftime     –     time.h
div     –     stdlib.h
div_t     –     stdlib.h
EDOM     –     errno.h
EOF     –     stdio.h
ERANGE     –     errno.h
errno     –     errno.h
exit     –     stdlib.h
EXIT_FAILURE     –     stdlib.h
EXIT_SUCCESS     –     stdlib.h
exp     –     math.h
fabs     –     math.h
fclose     –     stdio.h
feof     –     stdio.h
ferror     –     stdio.h
fflush     –     stdio.h
fgetc     –     stdio.h
fgetpos     –     stdio.h
fgets     –     stdio.h
FILE     –     stdio.h
FILENAME_MAX     –     stdio.h
floor     –     math.h
fmod     –     math.h
fopen     –     stdio.h
FOPEN_MAX     –     stdio.h
fpos_t     –     stdio.h
fprintf     –     stdio.h
fputc     –     stdio.h
fputs     –     stdio.h
fread     –     stdio.h
freopen     –     stdio.h
frexp     –     math.h
fscanf     –     stdio.h
fseek     –     stdio.h
fsetpos     –     stdio.h
ftell     –     stdio.h
fwrite     –     stdio.h
getc     –     stdio.h

You may also like

Leave a Comment