Whenever I ask people about the difference between an API and a library, I get different opinions. Some give this kind of definition, saying that an API is a spec and a library
A library contains re-usable chunks of code (a software program).
These re-usable codes of library is linked to your program through APIs
(Application Programming Interfaces). That is, API is interface to library through which re-usable codes are linked to an application program.
In simple term it can be said that an API is an interface between two software programs which facilitates the interaction between them.
For example, in procedural languages like C, the library math.c
contains the implementations of mathematical function, such as sqrt
, exp
, log
etc. It contains the definition of all these functions.
These function can be referenced by using the API math.h
which describes and prescribes the expected behavior.