Q:

C# program to demonstrate the #undef preprocessor directive

0

C# program to demonstrate the #undef preprocessor directive

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate the #undef preprocessor directive is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to demonstrate the #undef preprocessor directive.

#define MACRO1
#define MACRO2
#define MACRO3
#undef  MACRO2

using System;

class Program
{
   public static void Main()
    {
        #if (MACRO1)
            Console.WriteLine("MACRO1 is defined");
        #endif
        #if (MACRO2)
            Console.WriteLine("MACRO2 is defined");
        #endif
        #if (MACRO3)
            Console.WriteLine("MACRO3 is defined");
        #endif
    }
}

Output:

MACRO1 is defined
MACRO3 is defined
Press any key to continue . . .

Explanation:

In the above program, we defined three macros MACRO1MACRO2, and MACRO3. After that, we undefined the MACRO2 using the #undef pre-processor directive.

Here, we created a class Program that contains the Main() method. The Main() method is the entry point for the program. Here we checked macros are defined or not and print the appropriate message on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now