Switch case MCQ 11: Macro identifier (#define) in switch
Switch case MCQ 11: Macro identifier (#define) in switch
Problem Statement 11 : Macro identifier (#define) in switch
#include"stdio.h"
#define var 1
void main()
{
int choice = 1 ;
switch(choice)
{
case var:
printf("nAllas");
break;
case 2:
printf("nBabo");
break;
case 3:
printf("nHurray");
break;
}
}
Options : Guess the Output
- Babo
- Error : Variables are not allowed
- Hurray
- Allas
How ? Why ?
- #define is preprocessor
- Before Executing program Macro processor just replaces the ‘var’ by its eqivalent definition
- Here ‘var’ is replaced by 1 and case 1 will be executed
Select Switch Case Question :