3 What steps are required to use functions for the standard C, standard C++, and the math library? Use an example C/C++ program to illustrate your answer.
What will be an ideal response?
To use the features of standard C library no special compiler option is required. eg:
```
// use this program as a test
// the file is called hello.c
#include
int main()
{
printf("Hello World\n");
return 0;
}
To compile the above program use the following command:
gcc hello.c -o hello
To use the features of standard C++ a compiler option is required. eg:
// use this program as a test
// the file is called hello.cpp
#include
int main()
{
cout << "Hello World\n";
return 0;
}
To compile the above program use the following command:
gcc -lg++ -o hello hello.cpp
or
g++ -o hello hello.cpp
To use the math library a compiler option is required:
// use this program as a test
// the file is called power.c
#include
#include
int main()
{
printf("The square of 5 is %d",pow(5,2));
return 0;
}
To compile the above program use the following command:
gcc -lm -o power power.c
```