Tutorials, Free Online Tutorials,It Challengers provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, core java, sql, php, c language etc. for beginners and professionals.

Breaking

C Aptitude Questions And Answers - C PREPROCESSOR

---------------------------------- Test Your "C" Skill -------------------------------------

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

11.

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

main()
{
   int x;
   x=MAX(3+2,2+7);
   printf(“%d”,x);
}

Output:-  9

12.
#define PRINT(int) printf(“%d”,int)
main()
{
 int x=2,y=3,z=4;
 PRINT(x);
 PRINT(y);
 PRINT(z);
}

Output: 2 3 4

No comments:

Post a Comment