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程序预处理器的设计与实现

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542200.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

系统日志管理

1 查看系统中的日志 rsyslog 此服务是用来采集系统日志的&#xff0c;他不产生日志&#xff0c;只是起到采集作用 2 rsyslog 的管理 /var/log/messages服务信息日志/var/log/secuer系统登陆日志/var/log/cron定时任务日志/var/log/maillog邮件日志/var/log/boot.log系统启动日…

pythonassertbug_还在 Bug 不断?不妨试试这 2 个装X技巧

原标题&#xff1a;还在 Bug 不断&#xff1f;不妨试试这 2 个装X技巧作者 | luanhz来源 | 小数志(ID&#xff1a;Datazhi)程序员每天遇到 bug 就像喝水吃饭一样稀松平常&#xff0c;关键在于怎么高效而不失优雅的面对这些 bug&#xff01;所以&#xff0c;你还在固执的使用 tr…

iOS10 UI教程视图的边界与视图的框架

2019独角兽企业重金招聘Python工程师标准>>> iOS10 UI教程视图的边界与视图的框架 iOS10 UI视图的边界 在视图的几何形状中我们提到了视图属性中的一部分属性可以将定义的视图绘制在屏幕上。其中典型的3个属性为边界属性、框架属性以及中心位置属性。 bounds表示的就…

Java System类runFinalization()方法及示例

系统类runFinalization()方法 (System class runFinalization() method) runFinalization() method is available in java.lang package. runFinalization()方法在java.lang包中可用。 runFinalization() method is used to run the finalize() methods of any object that are…

Linux中远程文件的传输

1. scp命令 scp file userip:/dir 把自己主机的文件远程复制到其他主机 scp userip:/file dir 把其他主机的文件远程复制到当前主机 注意&#xff1a;要关闭接受端的防火墙 把主机的file远程复制到IP为172.25.254.117的root用户的Desktop 把IP为172.25.254.117的root用户Deskt…

svn: Can't convert string from 'UTF-8' to native

详见&#xff1a;http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt227 svn 版本库中有文件是以中文字符命名的&#xff0c;在 Linux 下 checkout 会报错&#xff1a; svn: Cant convert string from UTF-8 to native encoding 然后 checkout 程序就退出了&#xff…

引入antd组件样式_个人作品:一个技术栈koa2+ mysql+react + antd的个人博客

前言此项目是个人博客&#xff0c;有前端界面后台管理系统&#xff1b;目的是当做react和node的练手项目&#xff0c;同时还可以了解到服务器nginx部署web站点以及备案和域名的基本操作流程。项目预览地址https://www.lxsblog.cn​www.lxsblog.cnGitHub地址LinWeb/blog​github…

Java ObjectOutputStream writeLong()方法与示例

ObjectOutputStream类writeLong()方法 (ObjectOutputStream Class writeLong() method) writeLong() method is available in java.io package. writeLong()方法在java.io包中可用。 writeLong() method is used to write the given 8 bytes long value. writeLong()方法用于写…

浅谈Jfinal急速开发框架

2019独角兽企业重金招聘Python工程师标准>>> 使用Jfinal一段时间了,记得当初14年吧,为了建立一个简单的门户网站,想找个轻量型的急速开发框架,然后搜到Jfinal,然后用了一段时间后,确实不错, 现在吧,随着时间的推移,作者对JFinal的版本迭代也是一直在努力,一直朝着优…

make 怎么降级_Ubuntu 中将 make 的版本降低

最新的 Ubuntu 版本使用的是 make 版本是 4.0.在编译 Android4.4 源码包时&#xff0c;由于 make 版本过高&#xff0c;命令提示行会提示编译 Android4.4 源码包需要 make 的版本为 3.81 或 3.82.build/core/main.mk:42: ****************************************************…

Java ObjectOutputStream writeChar()方法与示例

ObjectOutputStream类writeChar()方法 (ObjectOutputStream Class writeChar() method) writeChar() method is available in java.io package. writeChar()方法在java.io包中可用。 writeChar() method is used to write 2 bytes of a character value. writeChar()方法用于写…

虚拟机的管理

我们采用虚拟机的原因是什么呢&#xff0c;很简单就俩字&#xff1a; 节能 1. 管理虚拟机的命令&#xff1a; virt-manager开启虚拟机管理器virsh list显示正在运行的虚拟机virsh list --all查看所有虚拟机virsh start desktop打开虚拟机virsh shutdown desktop正常关闭虚拟机…

mybatis对java自定义注解的使用——入门篇

转自&#xff1b;https://www.cnblogs.com/sonofelice/p/4980161.html 1. 最近在学习spring和ibatis框架。 以前在天猫实习时做过的一个小项目用到的mybatis&#xff0c;在其使用过程中&#xff0c;不加思索的用了比较原始的一种持久化方式&#xff1a; 在一个包中写一个DAO的接…

Java BigDecimal toBigIntegerExact()方法(带示例)

BigDecimal类的toBigIntegerExact()方法 (BigDecimal Class toBigIntegerExact() method) toBigIntegerExact() method is available in java.math package. toBigIntegerExact()方法在java.math包中可用。 toBigIntegerExact() method is used to convert this BigDecimal int…

Linux中的软件管理

1. 使用已有的网络安装资源安装软件 cd /etc/yum.repos.d/ (移动到yum源指向的文件配置目录下&#xff09; vim westos.repo &#xff08;新建文件&#xff0c;yum下后缀必须为.repo) 编辑这个文件里面写 [redhat] &#xff08;软件仓库名称&#xff09; namefirefox &#x…

楚留香ai人脸识别_戴口罩居然也能人脸识别?这些AI黑科技真的藏不住了.........

当人工智能遇见影像技术&#xff0c;将会释放出多少意想不到的巨大能量&#xff1f;「喔图知图实验室」瞄准当下的影像痛点&#xff0c;持续发力升级AI黑科技&#xff0c;带来两大必杀技——人脸识别再度升级、AI智能旋转校正。戴口罩也能识别——人脸识别升级戴口罩人脸识别如…

android--------Popupwindow的使用

2019独角兽企业重金招聘Python工程师标准>>> PopupWindow在Android.widget包下&#xff0c;项目中经常会使用到PopupWindow做菜单选项&#xff0c; PopupWindow这个类用来实现一个弹出框&#xff0c;可以使用任意布局的View作为其内容&#xff0c;这个弹出框是悬浮…

使用JavaScript中的示例的escape()函数

While transferring the data over the network or sometimes while saving data to the database, we need to encode the data. The function escape() is a predefined function in JavaScript, which encodes the given string. 在通过网络传输数据或有时将数据保存到数据库…

安装虚拟机的脚本

1. 先安装生成自动安装脚本的工具 yum install system-config-kickstart -y 2. 打开这个软件 system-config-kickstart 基本设置&#xff1a;更改时区为上海&#xff0c;设置root用户密码 2&#xff09;设置安装方法为网络安装&#xff0c;将共享的镜像文件地址正确填写 3&…

小小小游戏

写着玩 FlappyBird 视频:https://pan.baidu.com/s/1sljIR5z 游戏:https://pan.baidu.com/s/1ge8j7Ej 项目:https://pan.baidu.com/s/1eSysxpw Breakout 视频:https://pan.baidu.com/s/1gfhv4hd 项目:https://pan.baidu.com/s/1hs8xPly QBert 视频:https://pan.baidu.com/s/1s…