Write a macro to demonstrate #define, #if, #else preprocessor commands. 6m Jun 2010

By | August 25, 2016

Write a macro to demonstrate #define, #if, #else preprocessor commands. 6

 

 Code:

#include <stdio.h>
#define CHOICE 100
int my_int = 0;
#if (CHOICE == 100)
void set_my_int()
{ my_int = 35; }
#else
void set_my_int()
{
my_int = 27;
}
#endif
main ()
{
set_my_int();
clrscr();
printf(“%d\n”, my_int);
getch();
}

#include <stdio.h>
#define CHOICE 100
int my_int = 0;
#if (CHOICE == 100)
void set_my_int()
{ my_int = 35; }
#else
void set_my_int()
{
my_int = 27;
}
#endif
main ()
{
set_my_int();
clrscr();
printf("%d\n", my_int);
getch();
}

Screen Shots:

C_program_Preprocessor

C_program_Preprocessor_Out