---------------------------------- Test Your "C" Skill -------------------------------------
PRE PROCESSOR
PRE PROCESSOR
1. Identify the token pasting operator?
a) +
b) ++
c) #
d) ##
Output:- D
2.
#include<stdio.h>
#define MAX 15
int main(){
int num;
num = ++MAX;
printf("%d",num);
return 0;
}
a.15
b.16
c.compile error
d.run time error
Output:- compile error
3.
#define MAX (x, y) ((x) > (y) ? (x) : (y))
main()
{
int x=5, y = 5;
printf(“maximum is %d”, MAX( ++x, ++y));
}
a) Maximum is 7
b) Maximum is 5
c) Maximum is 6
d) None
Output:- A
4.
#define square (a) (a * a)
printf(“%d”, square (4 + 5));
a) 81
b) 4
c) 29
d) None
Output:- C
5.
#define SQR(x) (x * x)
main()
{
int a,b=3;
a=SQR(b+2);
printf(“\n%d”,a);
}
a. 25
b. 11
c. error
d. garbage value
Output:- B
6.
#define SQR(x)( (x) *( x))
main()
{
int a,b=3;
a=SQR(b+2);
printf(“\n%d”,a);
}
a. 25
b. 11
c. error
d. garbage value
Output:- a
7.
#define CUBE(x) (x * x * x)
main()
{
int a,b=3;
a=CUBE(b++);
printf(“\n %d %d”,a,b);
}
Output:- 27 6
8.
#define SWAP(a,b,c) (int t; t=a, a=b, b=t;)
main()
{
int x=10,y=20;
SWAP(x,y,int);
Printf(“%d %d”,x,y);
}
Output:- (int t; t=a, a=b, b=t;);
This code won’t compile since the declaration of t can’t take place within parenthesis.
9.How should you modify SWAP macro such that it can swap two integers?
Output:- #define SWAP(a,b,c) c t; t=a, a=b, b=t;
10.
#define MESS junk
void main(){ printf(“MESS”);}
Output:- MESS
No comments:
Post a Comment