# C Preprocessor Questions and Answers updated daily – C Language

11 C Preprocessor Questions and answers section with explanation for various online exam preparation, various interviews, C Language C Preprocessor online test. C Preprocessor Questions with detailed description, explanation will help you to master the topic.

## C Preprocessor Questions

1.
What will be the output of the program?

#include
#define MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c)

int main()
{
int x;
x = MAX(3+2, 2+7, 3+7);
printf("%dn", x);
return 0;
}        SHOW ANSWER
Correct Ans:10
Explanation:
The macro MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c) returns the biggest of given three numbers.

Step 1: int x; The variable x is declared as an integer type.

Step 2: x = MAX(3+2, 2+7, 3+7); becomes,

=> x = (3+2 >2+7 ? 3+2 > 3+7 ? 3+2 : 3+7: 2+7 > 3+7 ? 2+7 : 3+7)

=> x = (5 >9 ? (5 > 10 ? 5 : 10): (9 > 10 ? 9 : 10) )

=> x = (5 >9 ? (10): (10) )

=> x = 10

Step 3: printf("%dn", x); It prints the value of 'x'.

Hence the output of the program is "10".

2.
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;
}        SHOW ANSWER
Correct Ans:2,3,4
Explanation:
The macro PRINT(i) print("%d,", i); prints the given variable value in an integer format.

Step 1: int x=2, y=3, z=4; The variable x, y, z are declared as an integer type and initialized to 2, 3, 4 respectively.

Step 2: PRINT(x); becomes printf("%d,",x). Hence it prints '2'.

Step 3: PRINT(y); becomes printf("%d,",y). Hence it prints '3'.

Step 4: PRINT(z); becomes printf("%d,",z). Hence it prints '4'.

Hence the output of the program is 2, 3, 4.

3.

What will be the output of the program?

#include<stdio.h>
#define MESS junk

int main()
{
printf("MESSn");
return 0;
}        SHOW ANSWER
Correct Ans:MESS
Explanation:
printf("MESSn"); It prints the text "MESS". There is no macro calling inside the printf statement occured.

4.
What will be the output of the program?

#include<stdio.h>
#define MIN(x, y) (x<y)? x : y;
int main()
{
int x=3, y=4, z;
z = MIN(x+y/2, y-1);
if(z > 0)
printf("%dn", z);
return 0;
}        SHOW ANSWER
Correct Ans:3
Explanation:
The macro MIN(x, y) (x<y)? x : y; returns the smallest value from the given two numbers.

Step 1: int x=3, y=4, z; The variable x, y, z are declared as an integer type and the variable x, y are initialized to value 3, 4 respectively.

Step 2: z = MIN(x+y/2, y-1); becomes,

=> z = (x+y/2 < y-1)? x+y/2 : y - 1;

=> z = (3+4/2 < 4-1)? 3+4/2 : 4 - 1;

=> z = (3+2 < 4-1)? 3+2 : 4 - 1;

=> z = (5 < 3)? 5 : 3;

The macro return the number 3 and it is stored in the variable z.

Step 3: if(z > 0) becomes if(3 > 0) here the if condition is satisfied. It executes the if block statements.

Step 4: printf("%dn", z);. It prints the value of variable z.

Hence the output of the program is 3

5.
What will be the output of the program?

#include<stdio.h>
#define MAX(a, b) (a > b ? a : b)

int main()
{
int x;
x = MAX(3+2, 2+7);
printf("%dn", x);
return 0;
}        SHOW ANSWER
Correct Ans:9
Explanation:
The macro MAX(a, b) (a > b ? a : b) returns the biggest value of the given two numbers.

Step 1 : int x; The variable x is declared as an integer type.

Step 2 : x = MAX(3+2, 2+7); becomes,

=> x = (3+2 > 2+7 ? 3+2 : 2+7)

=> x = (5 > 9 ? 5 : 9)

=> x = 9

Step 3 : printf("%dn", x); It prints the value of variable x.

Hence the output of the program is 9.

6.
What will be the output of the program?

#include<stdio.h>
#define FUN(i, j) i##j

int main()
{
int va1=10;
int va12=20;
printf("%dn", FUN(va1, 2));
return 0;
}        SHOW ANSWER
Correct Ans:20
Explanation:
The following program will make you understand about ## (macro concatenation) operator clearly.

7.
What will be the output of the program?

#include<stdio.h>
#define CUBE(x) (x*x*x)

int main()
{
int a, b=3;
a = CUBE(b++);
printf("%d, %dn", a, b);
return 0;
}        SHOW ANSWER
Correct Ans:27,6
Explanation:
The macro function CUBE(x) (x*x*x) calculates the cubic value of given number(Eg: 103.)

Step 1: int a, b=3; The variable a and b are declared as an integer type and varaible b id initialized to 3.

Step 2: a = CUBE(b++); becomes

=> a = b++ * b++ * b++;

=> a = 3 * 3 * 3; Here we are using post-increement operator, so the 3 is not incremented in this statement.

=> a = 27; Here, 27 is store in the variable a. By the way, the value of variable b is incremented by 3. (ie: b=6)

Step 3: printf("%d, %dn", a, b); It prints the value of variable a and b.

Hence the output of the program is 27, 6.

8.
What will be the output of the program?

#include<stdio.h>
#define SQR(x)(x*x)

int main()
{
int a, b=3;
a = SQR(b+2);
printf("%dn", a);
return 0;
}        SHOW ANSWER
Correct Ans:11
Explanation:
The macro function SQR(x)(x*x) calculate the square of the given number 'x'. (Eg: 102)

Step 1: int a, b=3; Here the variable a, b are declared as an integer type and the variable b is initialized to 3.

Step 2: a = SQR(b+2); becomes,

=> a = b+2 * b+2; Here SQR(x) is replaced by macro to x*x .

=> a = 3+2 * 3+2;

=> a = 3 + 6 + 2;

=> a = 11;

Step 3: printf("%dn", a); It prints the value of variable 'a'.

Hence the output of the program is 11

9.
What will be the output of the program?

#include<stdio.h>
#define MAN(x, y) ((x)>(y)) ? (x):(y);

int main()
{
int i=10, j=5, k=0;
k = MAN(++i, j++);
printf("%d, %d, %dn", i, j, k);
return 0;
}        SHOW ANSWER
Correct Ans:12,6,12
Explanation:
The macro MAN(x, y) ((x)>(y)) ? (x):(y); returns the biggest number of given two numbers.

Step 1: int i=10, j=5, k=0; The variable i, j, k are declared as an integer type and initialized to value 10, 5, 0 respectively.

Step 2: k = MAN(++i, j++); becomes,

=> k = ((++i)>(j++)) ? (++i):(j++);

=> k = ((11)>(5)) ? (12):(6);

=> k = 12

Step 3: printf("%d, %d, %dn", i, j, k); It prints the variable i, j, k.

In the above macro step 2 the variable i value is increemented by 2 and variable j value is increemented by 1.

Hence the output of the program is 12, 6, 12

10.
In which stage the following code
#include<stdio.h>
gets replaced by the contents of the file stdio.h        SHOW ANSWER
Correct Ans:During preprocessing
Explanation:
The preprocessor replaces the line #include <stdio.h> with the system header file of that name. More precisely, the entire text of the file 'stdio.h' replaces the #include directive.

11.
What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?

#include<stdio.h>
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main()
{
int x=10, y=20;
SWAP(x, y, int);
printf("%d %dn", x, y);
return 0;
}        SHOW ANSWER
Correct Ans:Not compile
Explanation:
The code won't compile since declaration of t cannot occur within parenthesis.

Are you seeking for good platform for practicing C Preprocessor questions in online. This is the right place. The time you spent in Fresherslive will be the most beneficial one for you.

## Online Test on C Preprocessor @ Fresherslive

This page provides important questions on C Preprocessor along with correct answers and clear explanation, which will be very useful for various Interviews, Competitive examinations and Entrance tests. Here, Most of the C Preprocessor questions are framed with Latest concepts, so that you may get updated through these C Preprocessor Online tests. C Preprocessor Online Test questions are granted from basic level to complex level.

## Why To Practice C Preprocessor Test questions Online @ Fresherslive?

C Preprocessor questions are delivered with accurate answer. For solving each and every question, very lucid explanations are provided with diagrams wherever necessary.

Practice in advance of similar questions on C Preprocessor may improve your performance in the real Exams and Interview.

Time Management for answering the C Preprocessor questions quickly is foremost important for success in Competitive Exams and Placement Interviews.

Through Fresherslive C Preprocessor questions and answers, you can acquire all the essential idea to solve any difficult questions on C Preprocessor in short time and also in short cut method.

Winners are those who can use the simplest method for solving a question. So that they have enough time for solving all the questions in examination, correctly without any tense. Fresherslive provides most simplest methods to answer any tough questions. Practise through Fresherslive test series to ensure success in all competitive exams, entrance exams and placement tests.

## Why Fresherslive For C Preprocessor Online Test Preparation?

Most of the job seekers finding it hard to clear C Preprocessor test or get stuck on any particular question, our C Preprocessor test sections will help you to success in Exams as well as Interviews. To acquire clear understanding of C Preprocessor, exercise these advanced C Preprocessor questions with answers.

You're Welcome to use the Fresherslive Online Test at any time you want. Start your beginning, of anything you want by using our sample C Preprocessor Online Test and create yourself a successful one. Fresherslive provides you a new opportunity to improve yourself. Take it and make use of it to the fullest. GOODLUCK for Your Bright Future.

## Mock Test Premium Package

### ₹ 2200₹ 575

FreshersLive - No.1 Job site in India. Here you can find latest 2019 government as well as private job recruitment notifications for different posts vacancies in India. Get top company jobs for both fresher and experienced. Job Seekers can get useful interview tips, resume services & interview Question and answer. Practice online test free which is helpful for interview preparation. Register with us to get latest employment news/rojgar samachar notifications. Also get latest free govt and other sarkari naukri job alerts daily through E-mail.