• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Macro & Preprocessor

Question 1

C
#include <stdio.h>
#define PRINT(i, limit) do \\
                        { \\
                            if (i++ < limit) \\
                            { \\
                                printf(\"GeeksQuiz\\n\"); \\
                                continue; \\
                            } \\
                        }while(1)

int main()
{
    PRINT(0, 3);
    return 0;
}
How many times GeeksQuiz is printed in the above program?
  • 1
  • 3
  • 4
  • Compile-time error

Question 2

What is the output of following program? 

C
#include <stdio.h>
#define macro(n, a, i, m) m##a##i##n
#define MAIN macro(n, a, i, m)

int MAIN()
{
    printf(\"GeeksQuiz\");
    return 0;
}
  • Compiler Error

  • GeeksQuiz

  • MAIN

  • main

Question 3

C
#include <stdio.h>
#define X 3
#if !X
    printf(\"Geeks\");
#else
    printf(\"Quiz\");
 
#endif
int main()
{
        return 0;
}
  • Geeks
  • Quiz
  • Compiler Error
  • Runtime Error

Question 4

C
#include <stdio.h>
#define ISEQUAL(X, Y) X == Y
int main()
{
    #if ISEQUAL(X, 0)
        printf(\"Geeks\");
    #else
        printf(\"Quiz\");
    #endif
    return 0;
}
Output of the above program?
  • Geeks
  • Quiz
  • Any of Geeks or Quiz
  • Compile time error

Question 5

C
#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

Question 6

Output? C
# include <stdio.h>
# define scanf  \"%s Geeks Quiz \"
int main()
{
   printf(scanf, scanf);
   return 0;
}
  • Compiler Error
  • %s Geeks Quiz
  • Geeks Quiz
  • %s Geeks Quiz Geeks Quiz

Question 7

C
#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

Question 8

Output? C
#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

Question 9

Predict the output of following program? C
#include <stdio.h>
#define MAX 1000
int main()
{
   int MAX = 100;
   printf(\"%d \", MAX);
   return 0;
}
  • 1000
  • 100
  • Compiler Error
  • Garbage Value

Question 10

Output of following C program? C
#include<stdio.h>
#define max abc
#define abc 100

int main()
{
    printf(\"maximum is %d\", max);
    return 0;
}
  • maximum is 100
  • abcimum is 100
  • 100imum is 100
  • abcimum is abc

There are 21 questions to complete.

Last Updated :
Take a part in the ongoing discussion