C Pre-Processor - Aptitude Questions & Answers

C programming Pre-processor Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on Pre-processor topics like #define, #undef, #if, #endif etc.

1) What will be the output of following program ?
#include <stdio.h>
int main()
{
#ifdef debug
	printf("Start debugging...");
#endif
	printf("IncludeHelp");
	return 0;
}
  1. Start debugging...IncludeHelp
  2. IncludeHelp
  3. Error
  4. debug

2) What will be the output of following program ?
#include <stdio.h>
#define MAX 100
int main()
{
#define MAX 20
printf("MAX=%d...",MAX);
return 0;
}
  1. Error
  2. MAx=100...
  3. MAx=20...
  4. MAX=10020

3) What will be the output of following program ?
#include <stdio.h>
#define FUN(x)	x*x
int main()
{
int val=0;
val=128/FUN(8);
printf("val=%d",val);
return 0;
}
  1. 2
  2. 128
  3. 64
  4. 1


4) What will be the output of following program ?
#include <stdio.h>
#define FUN(x,y)	x##y
int main()
{
int a1=10,a2=20;
printf("%d...%d",FUN(a,1),FUN(a,2));
return 0;
}
  1. Error
  2. 10...10
  3. 20...20
  4. 10...20

5) What will be the output of following program ?
#include <stdio.h>
#define LARGEST(x,y)	(x>=y)?x:y
int main()
{
	int a=10,b=20,l=0;
	l=LARGEST(a++,b++);

	printf("a=%d,b=%d,largest=%d",a,b,l);
	return 0;
}
  1. a=10,b=20,largest=20
  2. a=11,b=21,largest=20
  3. a=11,b=21,largest=21
  4. a=11,b=22,largest=21

6) What will be the output of following program ?
#include <stdio.h>

#define OFF 0
#if debug == OFF
	int a=11;
#endif

int main()
{
	int b=22;
	printf("%d...%d",a,b);
	return 0;
}
  1. 11...22
  2. Error
  3. 11...11
  4. 22...22


7) What will be the output of following program ?
#include <stdio.h>
#define TEXT IncludeHelp
int main()
{
	printf("%s",TEXT);
	return 0;
}
  1. IncludeHelp
  2. TEXT
  3. Error
  4. TEXT IncludeHelp

8) What will be the output of following program ?
#include <stdio.h>
#define VAR1	VAR2+10
#define	VAR2	VAR1+20

int main()
{
	printf("%d",VAR1);
	return 0;
}
  1. VAR2+10
  2. VAR1+20
  3. Error
  4. 10

9) What will be the output of following program ?
#include <stdio.h>

#define SUM(x,y)	int s; s=x+y; printf("sum=%d\n",s);
int main()
{
	SUM(10,20);
	return 0;
}
  1. sum=30
  2. 10,20
  3. Error
  4. sum=0

10) What will be the output of following program ?
#include <stdio.h>
#define MAX	99
int main()
{
	printf("%d...",MAX);
#undef MAX
	printf("%d",MAX);
	return 0;
}
  1. 99...0
  2. 99...99
  3. Error
  4. MAX...MAX






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.