Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Preprocessor in C++

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 75
    Comment on it

    The preprocessor are the directives, which gives instruction to the compiler to do something before execution.

     

    C++  supports various preprocessors like #include, #define, #if, #else, #line, etc.

     

    The #define Preprocessor

    This directive creates the symbolic constants.

     

    #include <iostream>
    using namespace std;
    
    #define a 40;
    
    int main ()
    {
     
        cout << "Value of a :" << a << endl; 
    
        return 0;
    }

     

     

     Macros:

    You can use #define to define a macro used in the entire program.

     

    #include <iostream>
    using namespace std;
    
    #define MIN(a,b) (((a)<(b)) ? a : b)
    
    int main ()
    {
       int i, j;
       i = 100;
       j = 30;
       cout <<"The minimum is " << MIN(i, j) << endl;
    
        return 0;
    }

     

    Conditional Directives:

    These directives are used to check a certain condition you want.

     

    #ifndef NULL
       #define NULL 0
    #endif

     

    #include <iostream>
    using namespace std;
    #define DEBUG
    
    #define MIN(a,b) (((a)<(b)) ? a : b)
    
    int main ()
    {
       int i, j;
       i = 100;
       j = 30;
    #ifdef DEBUG
       cerr <<"Trace: Inside main function" << endl;
    #endif
    
    #if 0
       /* This is commented part */
       cout << MKSTR(HELLO C++) << endl;
    #endif
    
       cout <<"The minimum is " << MIN(i, j) << endl;
    
    #ifdef DEBUG
       cerr <<"Trace: Coming out of main function" << endl;
    #endif
        return 0;
    }

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: