The Big Master

Directives:

In C++, directives are instructions given to the preprocessor, which is a...

In C++, directives are instructions given to the preprocessor, which is a component of the compiler responsible for performing tasks before the actual compilation of the code begins.

Preprocessor Directive:

A preprocessor directive is an instruction to the compiler. A part of the compiler called the preprocessor deals with these directives before it begins the real compilation process.

 

Include Directive:

In C++, the #include directive is used to include external files or libraries in your program. It is a preprocessor directive that tells the compiler to insert the contents of the specified file at the location of the #include directive.

Header Files:

In C++, header files are files that contain declarations and definitions of functions, classes, constants, and other entities used in a C++ program. They serve as a way to provide interfaces to the functionalities and structures implemented in corresponding source code files.

iostream:

In C++, iostream is a standard header file that provides input and output functionality. It stands for “input-output stream.” The iostream header defines several predefined objects, such as cin and cout, which are used for console input and output operations.

Using directive:

In C++, the using directive is used to bring specific symbols from a namespace into the current scope.

using namespace std; // Brings all symbols from the std namespace into the current scope

 The #define Directive

Although the construction is not recommended in C++, constants can also be specified using the preprocessor directive #define. This directive sets up an equivalence between an identifier and a text phrase.

 

#define PI 3.14159              

This construction has long been popular in C. However, you can’t specify the data type of the constant using #define, which can lead to program bugs.

#include <iostream>
using namespace std ; 
#define PI 3.14159
int main() {
    double r = 5 ;
    double area = PI * r * r ;
    cout << "The area of the circle is: " << area << endl;
    return 0;
}
#include <iostream>
using namespace std;
int main()
{
    // program to convert paisas into rupees
    float rs = 10  , ps = 30  , ans  ;
    ans = rs  + ps / 100 ;	 
     cout << ans   << endl ;	
    return 0;
}
#include <iostream>
using namespace std;
int main()
{
    // program to convert rupees into paisas
    int rs = 10  , ps = 30  , ans  ;	
    ans = rs * 100 + ps  ;
     cout << ans   << endl ;	
    return 0;
}