Macro PreProcessor
Ques 1. what is the output for the below code?
#include <stdio.h>
#define min(x, y) x < y? x : y
int main()
{
int x=2, y=33, z;
z=min(x, y);
printf("\n min= %d", z);
return 0;
}
options:
A. 2
B. 33
C. compile time error
D. run time error
Ques 2. what is the output for the below code?
#include <stdio.h>
#define BIT
int main()
{
#ifdef BIT
printf("\n BIT ");
#elif
printf("\n BYTE);
#else
printf("\n word);
#endif
return 0;
}
options:
A. BIT
B. BYTE
C. word
D. compile time error
Ques 3. what is the output for the below code?
#include <stdio.h>
#define BYTE
#if BIT
#define BIT 1
#else
#define BYTE 8
#endif
int main()
{
printf("\n BIT = %d" ,BIT);
return 0;
}
options:
A. 1
B. 8
C. runtime error
D. Compile time error
Ques 4. what is the output for the below code?
#include <stdio.h>
#define xy(x,y) x##y
int main()
{
printf("\n XY = %d" ,xy(2,3));
return 0;
}
options:
A. 2
B. 3
C. 23
D. compile time error
Ques 5. what is the output for the below code?
#include <stdio.h>
#define M 3
#if M
printf("\n ptinstitute.in");
#else
printf("\n welcome");
#endif
int main()
{
return 0;
}
options:
A. Compile time error
B. ptinstitute.in
C. welcome
D. run time error
Ques 6. what is the output for the below code?
#include <stdio.h>
#define MAX(a,b) a>b?a:b
int main()
{
int a=2,b=3,c=4,d=6,z;
z=MAX(a+b, c+d);
printf("\n z=%d",z);
return 0;
}
options:
A. 5
B. 10
C. 4
D. 6
Ques 7. what is the output for the below code?
#include <stdio.h>
#define setbit(x,bitno) x=(x | (1<<bitno))
int main()
{
int a=0x3;
setbit(a, 3);
printf("\n a=%x",a);
return 0;
}
options:
A. b
B. 11
C. 31
D. compile time error
Ques 8. what is the output ?
#include <stdio.h>
#define resetbit(x,bitno) x=(x & ~(1<<bitno))
int main()
{
int a=0x1f;
resetbit(a, 2);
printf("\n a=%x",a);
return 0;
}
options:
A. compile time error
B. 2f
C. 1f
D. 1b
Ques 9. what is the output for the below code?
#include <stdio.h>
#define togglebit(x,bitno) x=(x ^ (1<<bitno))
int main()
{
int a=0x1b;
togglebit(a, 2);
printf("\n a=%x",a);
return 0;
}
options:
A. 1c
B. 1b
C. 1f
D. 1d
Ques 10. what is the output for the below code?
#include <stdio.h>
#define cube(x) x*x*x
int main()
{
int x=3;
x = 9/cube(x);
printf("%d", x);
return 0;
}
options:
A. 0
B. 27
C. 0.333
D. compile time error
Ques 11. what is the output?
#include <stdio.h>
#define compute(x) x*x+3 x++
int main()
{
int x=3;
x = compute(x);
printf("%d", x);
return 0;
}
options:
A. 13
B. 12
C. Compile time error
D. run time error
Ques 12. what is the output?
#include <stdio.h>
# define getch "%s Good morning "
int main()
{
printf(getch, getch);
return 0;
}
options:
A. %s Good morning %s Good morning
B. run time error
C. Compile time error
D. %s Good morning Good morning
Ques 13. what is the output for the below code?
#include <stdio.h>
#define ABC 10
#define ABC 22
int main()
{
printf("%d ",ABC);
#define ABC 33
printf("%d ",ABC);
return 0;
}
options:
A. Compile time error
B. 10 33
C. 22 33
D. run time error
Ques 14. what is the output for the below code?
#include <stdio.h>
#define len(len,gth) len##gth
int main()
{
int length = 100, breadth=4,a;
a=len(len, gth)* breadth;
printf("%d", a);
return 0;
}
options:
A. 400
B. compile time error
C. run time error
D. 25
Ques 15. what is the output for the below code?
#include <stdio.h>
#define abc(x,y) x+y * x-y
int main()
{
int a;
a=abc(3,4);
printf("%d", a);
return 0;
}
options:
A. 11
B. -7
C. -1
D. 17
Answers
1. A
2. A
3. C
4. C
5. A
6. B
7. A
8. D
9. C
10. B
11. C
12. D
13. C
14. A
15. A