Top

C Preprocessor

11.

What will be the output of the following C code?

#define sqr(x) x*x
main()
{
    int a1;
    a1=25/sqr(5);
    printf("%d",a1);
}

 

Answer: A

The output of the code shown above is 25. This is because the arithmetic statement takes the form of: 25/5*5 (which is equal to 1). If the macro had been defined as #define sqr(x) (x*x), the output would have been 1.

Enter details here

12.

After preprocessing when the program is sent for compilation the macros are removed from the expanded source code.

Answer: A

No answer description available for this question.

Enter details here

Answer: A

No answer description available for this question.

Enter details here

14.

What will be the output of the following C code?

#include 
#define a 2
main()
{
    int r;
    #define a 5
    r=a*2;
    printf("%d",r);
}

 

Answer: A

No answer description available for this question.

Enter details here

15.

What will be the output of the following C code?

#include
#define max 100
main()
{
    #ifdef max
    printf("hello");
}

 

Answer: D

The code shown above results in an error. This is because the preprocessor #endif is missing in the above code. If the identifier is defined, then the statements following #ifdef are executed till #endif is encountered.

Enter details here

16.

A macro must always be defined in capital letters.

Answer: B

FALSE, The macro is case insensitive.

Enter details here

17.

What will be the output of the following C code?

#include
#define max 100
void main()
{
    #if(max)
    printf("san");
    #endif
    printf("foundry");
}

 

Answer: D

The code shown above is an illustration of the preprocessor directive #if. The value of the defined identifier max is 100. On checking the condition (100510==), which is true, the statements after #if are executed till #endif is encountered. Hence the output is sanfoundry.

Enter details here

Answer: C

preprocessor directive is a message from programmer to the preprocessor.

Enter details here

19.

#include 
#define square(x) x*x
int main()
{
  int x;
  x = 36/square(6);
  printf("%d", x);
  return 0;
}

 

Answer: B

No answer description available for this question.

Enter details here

20.

What will be the output of the program?

#include
#define PRINT(i) printf("%d,",i)

int main()
{
    int x=2, y=3, z=4;
    PRINT(x);
    PRINT(y);
    PRINT(z);
    return 0;
}

 

Answer: A

No answer description available for this question.

Enter details here

Loading…
Tags: C Preprocessor Questions and Answers || C Preprocessor MCQ Questions and Answers || C Preprocessor GK Questions and Answers || C Preprocessor GK MCQ Questions || C Preprocessor Multiple Choice Questions and Answers || C Preprocessor GK || GK on C Preprocessor || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming