Exercise: Questions on Macro & Preprocessor


Questions on Macro & Preprocessor : Question 1 :
 #include <stdio.h>
 #define PRINT(i, limit) do \
                         { \
                             if (i++ < limit) \
                             { \
                                 printf("PROcoder\n"); \
                                 continue; \
                             } \
                         }while(1)
 
 int main()
 {
     PRINT(0, 3);
     return 0;
 }
 
How many times PROcoder is printed in the above program?

1
3
4
Compile-time error
Show Answer
Questions on Macro & Preprocessor : Question 2 :
#include <stdio.h>
#if X == 3
    #define Y 3
#else
    #define Y 5
#endif

int main()
{
    printf("%d", Y);
    return 0;
}
What is the output of the above program?

3
5
3 or 5 depending on value of X
Compile time error
Show Answer
Questions on Macro & Preprocessor : Question 3 :
What is the output of following program?
 #include <stdio.h>
 #define macro(n, a, i, m) m##a##i##n
 #define MAIN macro(n, a, i, m)
 
 int MAIN()
 {
     printf("PROcoder");
     return 0;
 }
 
 

Compiler Error
PROcoder
MAIN
main
Show Answer
Questions on Macro & Preprocessor : Question 4 :
 #include <stdio.h>
 #define X 3
 #if !X
     printf("PRO");
 #else
     printf("coder");
  
 #endif
 int main()
 {
         return 0;
 }
 

PRO
coder
Compiler Error
Runtime Error
Show Answer
Questions on Macro & Preprocessor : Question 5 :
 #include <stdio.h>
 #define ISEQUAL(X, Y) X == Y
 int main()
 {
     #if ISEQUAL(X, 0)
         printf("PRO");
     #else
         printf("coder");
     #endif
     return 0;
 }
 
Output of the above program?

PRO
coder
Any of PRO or coder
Compile time error
Show Answer
Questions on Macro & Preprocessor : Question 6 :
#include <stdio.h>
#define square(x) x*x
int main()
{
  int x;
  x = 36/square(6);
  printf("%d", x);
  return 0;
}

1
36
0
Compiler Error
Show Answer
Questions on Macro & Preprocessor : Question 7 :
Output?
 # include <stdio.h>
 # define scanf  "%s PRO coder "
 int main()
 {
    printf(scanf, scanf);
    return 0;
 }
 

Compiler Error
%s PRO coder
PRO coder
%s PRO coder PRO coder
Show Answer
Questions on Macro & Preprocessor : Question 8 :
#include <stdio.h>
#define a 10
int main()
{
  printf("%d ",a);

  #define a 50

  printf("%d ",a);
  return 0;
}

Compiler Error
10 50
50 50
10 10
Show Answer
Questions on Macro & Preprocessor : Question 9 :
Output?
#include<stdio.h> 
#define f(g,g2) g##g2 
int main() 
{ 
   int var12 = 100; 
   printf("%d", f(var,12)); 
   return 0; 
}

100
Compiler Error
0
1
Show Answer
Questions on Macro & Preprocessor : Question 10 :
Which file is generated after pre-processing of a C program?

.p
.i
.o
.m
Show Answer