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.pswp.cn/news/542200.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542200.shtml
英文地址,請注明出處:http://en.pswp.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…