• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Macro & Preprocessor

Question 11

C
#include <stdio.h>
#define get(s) #s

int main()
{
    char str[] = get(GeeksQuiz);
    printf(\"%s\", str);
    return 0;
}
  • Compiler Error
  • #GeeksQuiz
  • GeeksQuiz
  • GGeeksQuiz

Question 12

What is the output for the following code snippet? CPP
#include<stdio.h>
#define A -B
#define B -C
#define C 5

int main()
{
  printf(\"The value of A is %d\\n\", A); 
  return 0;
} 
This question is contributed by Aastha Anand.
  • The value of A is 4
  • The value of A is 5
  • Compilation Error
  • Runtime Error

Question 13

Suppose someone writes increment macro (i.e. which increments the value by one) in following ways: C
#define INC1(a) ((a)+1)

#define INC2 (a) ((a)+1)

#define INC3( a ) (( a ) + 1)

#define INC4 ( a ) (( a ) + 1)
Pick the correct statement for the above macros.
  • Only INC1 is correct.
  • All (i.e. INC1, INC2, INC3 and INC4) are correct.
  • Only INC1 and INC3 are correct.
  • Only INC1 and INC2 are correct.

Question 14

The following program won’t compile because there’re space between macro name and open parenthesis. C
#include \"stdio.h\"

#define MYINC   (  a  )  (  ( a )  +  1 )

int main()
{

 printf(\"GeeksQuiz!\");

 return 0;
}
  • TRUE
  • FALSE

Question 15

Consider the following statements
#define hypotenuse (a, b) sqrt (a*a+b*b); 
The macro call hypotenuse(a+2,b+3);
  • Finds the hypotenuse of a triangle with sides a+2 and b+3
  • Finds the square root of (a+2)2 and (b+3)2
  • Is invalid
  • Find the square root of 3*a + 4*b + 5

Question 16

What is the output of the following C program? C
#include<stdio.h>
#define SQR(x) (x*x)
int main()
{
    int a;
    int b=4;
    a=SQR(b+2);
    printf(\"%d\\n\",a);
    return 0;
}
  • 14
  • 36
  • 18
  • 20

Question 17

The translator which performs macro calls expansion is called: 
 

  • Macro processor
     

  • Micro pre - processor
     

  • Macro pre - processor
     

  • Dynamic Linker
     

Question 18

What is the use of "#pragma once"?
 

  • Used in a header file to avoid its inclusion more than once.
     

  • Used to avoid multiple declarations of same variable.
     

  • Used in a c file to include a header file at least once.
     

  • Used to avoid assertions
     

Question 19

Which file is generated after pre-processing of a C program?
 

  • .p
     

  • .i
     

  • .o
     

  • .m
     

Question 20

Typically, library header files in C (e.g. stdio.h) contain not only declaration of functions and macro definitions but they contain definition of user defined data types (e.g. struct, union etc), typedefs and definition of global variables as well. So if we include the same header file more than once in a C program, it would result in compile issue because re-definition of many of the constructs of the header file would happen. So it means the following program will give compile error. 
 

C
#include “stdio.h”
#include “stdio.h”
#include “stdio.h”

int main()
{
 printf(Whether this statement would be printed?)
 return 0;
}
  • TRUE
     

  • FALSE
     

There are 21 questions to complete.

Last Updated :
Take a part in the ongoing discussion