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 debugprintf("Start debugging..."); #endifprintf("IncludeHelp");return 0; }Start debugging...IncludeHelp
IncludeHelp
Error
debug
IncludeHelp
debug macro is not define. 1)以下程序的輸出是什么?
開始調試...包括幫助
包括幫助
錯誤
調試
包括幫助
調試宏未定義。 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; }
Error
MAx=100...
MAx=20...
MAX=10020
MAX=20...
A macro can be redefine any where. 2)以下程序的輸出是什么?
錯誤
MAx = 100 ...
MAx = 20 ...
最大值= 10020
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; }
2
128
64
1
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)以下程序的輸出是什么?
2
128
64
1個
128
考慮一下表達式...
val = 128 / FUN(8)=>將展開val = 128/8 * 8
根據運算符的關聯性,“ /”將首先計算,因此表達式將為val =(128/8)* 8 => 128 .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} 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; }
Error
10...10
20...20
10...20
10...20
we can concatenate variable like this x##y .. (a##1=a1). 4)以下程序的輸出是什么?
錯誤
10 ... 10
20 ... 20
10 ... 20
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; }
a=10,b=20,largest=20
a=11,b=21,largest=20
a=11,b=21,largest=21
a=11,b=22,largest=21
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)以下程序的輸出是什么?
a = 10,b = 20,最大= 20
a = 11,b = 21,最大= 20
a = 11,b = 21,最大= 21
a = 11,b = 22,最大= 21
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 == OFFint a=11; #endifint main() {int b=22;printf("%d...%d",a,b);return 0; }
11...22
Error
11...11
22...22
11...22
Undefined macro has 0, you can use undefined macro name in #if...#endif. 6)以下程序的輸出是什么?
11 ... 22
錯誤
11 ... 11
22 ... 22
11 ... 22
未定義的宏有0,您可以在#if ...#endif中使用未定義的宏名稱。 .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} 7) What will be the output of following program ? #include <stdio.h> #define TEXT IncludeHelp int main() {printf("%s",TEXT);return 0; }
IncludeHelp
TEXT
Error
TEXT IncludeHelp
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)以下程序的輸出是什么?
包括幫助
文本
錯誤
TEXT IncludeHelp
錯誤:“ 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+20int main() {printf("%d",VAR1);return 0; }
VAR2+10
VAR1+20
Error
10
Error : 'VAR1' undeclared identifier.
8)以下程序的輸出是什么?
VAR2 + 10
VAR1 + 20
錯誤
10
錯誤:“ 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; }
sum=30
10,20
Error
sum=0
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)以下程序的輸出是什么?
總和= 30
10,20
錯誤
總和= 0
總和= 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 MAXprintf("%d",MAX);return 0; }
99...0
99...99
Error
MAX...MAX
Error: 'MAX' undeclared identifier
After #undef you can not use that macro. 10)以下程序的輸出是什么?
99 ... 0
99 ... 99
錯誤
最大...最大
錯誤:“ MAX”個未聲明的標識符
#undef之后,您將無法使用該宏。
翻譯自: https://www.includehelp.com/c-programs/c-pre-processor-aptitude-questions-and-answers.aspx
c程序預處理器的設計與實現
總結
以上是生活随笔為你收集整理的c程序预处理器的设计与实现_C预处理器-能力问题与解答的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java OutputStreamWri
- 下一篇: abap 添加alv上的工具栏的按钮_神