c程序预处理器的设计与实现_C预处理器-能力问题与解答

c程序预处理器的设计与实现

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.

C编程预处理程序能力问题和解答:在本节中,您将找到有关预处理程序主题的C能力倾向问题和解答,例如#define,#undef,#if,#endif等。

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

Answer
Correct Answer - 2
IncludeHelp
debug macro is not define.
1)以下程序的输出是什么?
  1. 开始调试...包括帮助

  2. 包括帮助

  3. 错误

  4. 调试

回答
正确答案-2
包括帮助
调试宏未定义。
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

Answer
Correct Answer - 3
MAX=20...
A macro can be redefine any where.
2)以下程序的输出是什么?
  1. 错误

  2. MAx = 100 ...

  3. MAx = 20 ...

  4. 最大值= 10020

回答
正确答案-3
MAX = 20 ...
宏可以在任何地方重新定义。
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

Answer
Correct Answer - 2
128
Consider the expression...
val=128/FUN(8) => will expand val=128/8*8
According to the operator associativity "/" will evaluate first so expression will be val=(128/8)*8=>128
3)以下程序的输出是什么?
  1. 2

  2. 128

  3. 64

  4. 1个

回答
正确答案-2
128
考虑一下表达式...
val = 128 / FUN(8)=>将展开val = 128/8 * 8
根据运算符的关联性,“ /”将首先计算,因此表达式将为val =(128/8)* 8 => 128
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

Answer
Correct Answer - 4
10...20
we can concatenate variable like this x##y .. (a##1=a1).
4)以下程序的输出是什么?
  1. 错误

  2. 10 ... 10

  3. 20 ... 20

  4. 10 ... 20

回答
正确答案-4
10 ... 20
我们可以像x ## y ..(a ## 1 = a1)那样连接变量。
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

Answer
Correct Answer - 4
a=11,b=22,largest=21
Consider the expression
(x>=y)?x:y => will expand with values a++ and b++
(a++ >= b++)? a++ : b++; here (10 >= 20 )?11:21; [largest will be 21..]
Since b++ is executing 2 times so value of b will be 22.
5)以下程序的输出是什么?
  1. a = 10,b = 20,最大= 20

  2. a = 11,b = 21,最大= 20

  3. a = 11,b = 21,最大= 21

  4. a = 11,b = 22,最大= 21

回答
正确答案-4
a = 11,b = 22,最大= 21
考虑表达
(x> = y)?x:y =>将使用值a ++和b ++扩展
(a ++> = b ++)? a ++:b ++; 这里(10> = 20)?11:21; [最大为21 ..]
由于b ++执行2次,因此b的值为22。
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

Answer
Correct Answer - 1
11...22
Undefined macro has 0, you can use undefined macro name in #if...#endif.
6)以下程序的输出是什么?
  1. 11 ... 22

  2. 错误

  3. 11 ... 11

  4. 22 ... 22

回答
正确答案-1
11 ... 22
未定义的宏有0,您可以在#if ...#endif中使用未定义的宏名称。
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

Answer
Correct Answer - 3
Error : 'IncludeHelp' undeclared identifier.
Consider the statement printf("%s",TEXT); , TEXT is a macro will expand like printf("%s",IncludeHelp);, in this statement IncludeHelp should be an identifier.
7)以下程序的输出是什么?
  1. 包括帮助

  2. 文本

  3. 错误

  4. TEXT IncludeHelp

回答
正确答案-3
错误:“ IncludeHelp”未声明的标识符。
考虑语句 printf(“%s”,TEXT); ,TEXT是一个宏,它将像 printf(“%s”,IncludeHelp)一样展开; ,在此语句中,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

Answer
Correct Answer - 3
Error : 'VAR1' undeclared identifier.
8)以下程序的输出是什么?
  1. VAR2 + 10

  2. VAR1 + 20

  3. 错误

  4. 10

回答
正确答案-3
错误:“ VAR1”未声明的标识符。
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

Answer
Correct Answer - 1
sum=30
Here SUM(10,20) will be expanded as int s; s=10+20; printf("sum=%d",s);
Hence sum=30 will print.
In same example, if you call SUM() again, you will get an error 's' redefinition.
9)以下程序的输出是什么?
  1. 总和= 30

  2. 10,20

  3. 错误

  4. 总和= 0

回答
正确答案-1
总和= 30
在这里, SUM(10,20)将被扩展为 int s; s = 10 + 20; printf(“ sum =%d”,s);
因此将打印sum = 30。
在同一示例中,如果再次调用SUM(),则会得到错误的's'重定义。
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

Answer
Correct Answer - 3
Error: 'MAX' undeclared identifier
After #undef you can not use that macro.
10)以下程序的输出是什么?
  1. 99 ... 0

  2. 99 ... 99

  3. 错误

  4. 最大...最大

回答
正确答案-3
错误:“ MAX”个未声明的标识符
#undef之后,您将无法使用该宏。

翻译自: https://www.includehelp.com/c-programs/c-pre-processor-aptitude-questions-and-answers.aspx

c程序预处理器的设计与实现

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值