+ 6

What's the difference between a library and function?

I have been seeing these words on my guide but don't have a clear understanding. If possible please provide examples

18th Mar 2018, 12:32 PM
Ronald Mbanjwa
Ronald Mbanjwa - avatar
4 odpowiedzi
+ 4
@chirag answer is wrong. a function is a set of instructions that can be executed by calling the function, example: int sum(int a, int b) { return a+b; } main () { cout<<sum(5,3); //outputs 8 } A library is usually a set of classes and functions that are made by other people to make your like easier, for example c++ comes with the standard library which contains classes for input and output, data stream, containers and orther utilities. There are also third-party libraries like the boost library or sfml
18th Mar 2018, 1:05 PM
Marco
Marco - avatar
+ 3
@Chirag meaning libraries act as a container of functions?
18th Mar 2018, 12:41 PM
Ronald Mbanjwa
Ronald Mbanjwa - avatar
+ 2
@Marco thanks I now fully have an idea
18th Mar 2018, 1:56 PM
Ronald Mbanjwa
Ronald Mbanjwa - avatar
0
Functions are meant to do a specific task. Libraries contain the predefined functions provided by the programming language.
18th Mar 2018, 12:39 PM
cHiRaG GhOsH
cHiRaG GhOsH - avatar