#include directive – Preprocessor for header inclusion – CSKC
Sign In

Search

Code Learning #CPP#4572    siteicon   siteicon  

#include directive – Preprocessor for header inclusion

Understanding the purpose of include preprocessor

Learning Objectives

  • Observing specific pre-processor directives #include for inclusion of header files relevant to function and objects we are going to use in our program.

Source Code

TC++ #4572

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

Code Understanding

#include <iostream>
This include is there to use iostream function and objects like cout, cin, end etc.

#include <math.h>
This pre-processor include directive is for including the math related functions in this program. This helps is using functions like sqrt(), sin(), cos(), pow() etc.

using namespace std;
int main()
{
cout<<sqrt(25)<<endl;
Here we have been able to use sqrt function because math.h is included.

return 0;
}

Notes

  • iostream inclusion is most common in C++ programs. Some compilers include them by default.
  • some compiler may allow only modern version header files. Like only <iostream> may be allowed in place of <iostream.h> (The older version).
  • The latest version header file for math functions is <cmath> instead of older version <math.h>

 

Common Errors

  • Forgetting relevant inclusion is most common error.
  • Sometimes a program may compile on one compiler but not on another one. This may be due to inclusion differences. For e.g. strlen() may work only when string,h is included, but on some compiler it may be included by default.


Suggested Filename(s): pp-incl.cpp, include-directive.cpp



Share

Created: 1-Sep-2018 20:15 | Updated: 19-Nov-2018 16:11|