0

I'm confused about these two terms: Library and Headers.

Headers contain function definitions as far as I know, but I don't have any concept of Library. I'm a new programmer and have worked with C language a little. I am now learning C# so keep explanations in simple terms. If possible provide examples also as I've tried this link:

What's the difference between a header file and a library?

But I am unable to make an exact picture of these terms in mind.

Community
  • 1
  • 1
Wajiha Ali
  • 21
  • 4

1 Answers1

0

As the link say, the interface (header) tells you how to call some functionality (without knowing how it works), while the implementation (library) is the actual functionality.

Example: To use the printf function you need to include the header and the tells you how to call the printf function. It says, printf can be called like this

int printf ( const char * format, ... );

The library is the one which implements it

int printf ( const char * format, ... )
{
    ...
    ...
    ...
}

One more example: On linux, if you want to work with xml file, there is libxml library. Suppose, if you want to read a xml file, there are function exposed like

xmlTextReaderRead,  `xmlReaderForFile` etc...

These function are declare in the header file <libxml/xmlreader.h> means this <libxml/xmlreader.h> header tells you how to call the above said function, mean what parameters this function takes and what is its return value.

The library libxm2 implements these function and you have to link this library when you compile the code.