Friday, March 19, 2021

Preprocessor directives in C++

 Understanding the meaning and use of Preprocessor directives in C++

The example of the very basic C++ program
 can be a hello world program...

           fig 1             

The program started with #(hash) include and this contains the iostream(this is standard input output stream). This #include is called "preprocessor directive" , there can be many preprocessor directives in a program and that is added first in the program. other examples of preprocessor directives are #define, #ifndef  etc.

-) what is the use of  #include  ?
This #include is the way of including the standard and user defined 
files in the program that is from the outside sources and these standard and user defined files contains pieces of codes that can perform certain tasks. And this "#" (hash) has a role to provide a path between these standard or user defined files and preprocessors. And "include" adds the extra code to the program while the program preprocessed before compilation.


       Understanding with example in  fig-1   

In fig-1, there is a header file #include<iostream> the iostream is a standard file that contains methods that performs certain function whenever called. This iostream contains method like cout , cin, etc. , so in the example in fig-1 cout<<"hello world!"; is  there inside the main function so when the program is to be executed , it first looks for if there is preprocessor directives before compiling the program. If preprocessor directive is found then first program is preprocessed and then it is compiled. so #  provide the preprocessor the path to preprocess the files included and this "include" will include the code for cout method that is defined in standard input output stream.                                          

case if there is no preprocessor directive 

when there is no preprocessor directive in the program , no such method or function can be defined and used inside the main function that is included in some standard files or user defined files. such program can look like this...
                                                            
        
following program doesn't contain any preprocessor directive ,so no such method that is defined inside that file will be used inside the main function. This program will get compiled and there will be no preprocessing as there is no such preprocessor directives present.
           

                                                                              




       Author   
   Md wasif



Join the CodifiedYOUTH community to learn free skills and get free internships and lot more
Join on Whatsapp
Join on Linkedin
visit CodifiedYOUTH website for more detail

No comments:

Post a Comment

Using namespace std;

  Understanding "Using namespace std; namespace is a declarative region that provide scope to identifiers and is used to avoid the name...