Switch case MCQ 11: Macro identifier (#define) in switch

January 28, 2025 No Comments » Hits : 48






Switch case MCQ 11: Macro identifier (#define) in switch

Problem Statement 11 : Macro identifier (#define) in switch
#include"stdio.h"#define var 1void 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
  1. Babo
  2. Error : Variables are not allowed
  3. Hurray
  4. Allas



How ? Why ?
  1. #define is preprocessor
  2. Before Executing program Macro processor just replaces the ‘var’ by its eqivalent definition 
  3. Here ‘var’ is replaced by 1 and case 1 will be executed

Select Switch Case Question :


Bookmark & Share



Leave A Response