青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 47, 文章 - 10, 評論 - 8, 引用 - 0
數據加載中……

C語言高級測試:為C程序員準備的0x10個最佳問題

整個測試遵循以下的約定:

u ?????? 假定在所有的程序中必須的頭文件都已經被正確包含。

考慮如下的數據類型:

u ?????? char 1 個字節

u ?????? int 4 個字節

u ?????? long int 4 個字節

u ?????? float 4 個字節

u ?????? double 為個 8 字節

u ?????? long double 8 個字節

u ?????? 指針為 4 個字節
1. Consider the following program:

?1 #include < setjmp.h >
?2 static ?jmp_buf??buf;
?3 main()
?4 {
?5 ?? volatile ?? int ?b;
?6 ??b? = 3 ;
?7 ?? if (setjmp(buf) != 0 )??
?8 ?? {
?9 ????printf( " %d? " ,?b);??
10 ????exit( 0 );
11 ??}

12 ??b = 5 ;
13 ??longjmp(buf?,? 1 );
14 }
The output for this program is: ?

(a) 3
(b) 5
(c) 0
(d) None of the above

2. Consider the following program:
?1main()
?2{
?3???struct?node?
?4???{
?5?????int?a;
?6?????int?b;
?7?????int?c;?????
?8???}
;
?9???struct?node??s=?{?3,?5,6?};
10???struct?node?*pt?=?&s;
11???printf("%d"?,??*(int*)pt);
12}
The output for this program is:
(a) 3
(b) 5
(c) 6
(d) 7

3. Consider the following code segment:
?1int??foo?(?int?x?,?int??n)
?2{
?3??int?val;
?4??val?=1;
?5??if?(n>0)?
?6??{
?7????if?(n%2?==?1)??val?=?val?*x;
?8????val?=?val?*?foo(x*x?,?n/2);
?9??}

10??return?val;
11}

What function of x and n is compute by this code segment?? ?

(a) x^n
(b) x*n
(c) n^x
(d) None of the above

4. Consider the following program:

1 main()
2 {
3 ?? int ??a[ 5 ]? = ? { 1 , 2 , 3 , 4 , 5 } ;
4 ?? int ? * ptr? = ??( int * )( & a + 1 );
5 ??printf( " %d?%d " ?,? * (a + 1 ),? * (ptr - 1 )?);
6 }

The output for this program is:

(a) 2 2
(b) 2 1
(c) 2 5
(d) None of the above

5. Consider the following program:

?1 void ?foo( int ?[][ 3 ]?);?????
?2 main()
?3 {
?4 ?? int ?a?[ 3 ][ 3 ] = ? {? {? 1 , 2 , 3 } ?,? {? 4 , 5 , 6 } , { 7 , 8 , 9 } } ;
?5 ??foo(a);
?6 ??printf( " %d " ?,?a[ 2 ][ 1 ]);
?7 }

?8
?9 void ?foo(? int ?b[][ 3 ])
10 {
11 ?? ++ ?b;
12 ??b[ 1 ][ 1 ]? = 9 ;
13 }

The output for this program is:
(a) 8
(b) 9
(c) 7
(d) None of the above

6. Consider the following program:

?1 main()
?2 {
?3 ?? int ?a,?b,c,?d;
?4 ??a = 3 ;
?5 ??b = 5 ;
?6 ??c = a,b;
?7 ??d = (a,b);
?8 ??printf( " c=%d " ?,c);
?9 ??printf( " d=%d " ?,d);
10 }

11

The output for this program is:

(a) c=3 d=3
(b) c=5 d=3
(c) c=3 d=5
(d) c=5 d=5

7. Consider the following program:

1 main()
2 {
3 ?? int ?a[][ 3 ]? = ? {? 1 , 2 , 3 ?, 4 , 5 , 6 } ;
4 ?? int ?( * ptr)[ 3 ]? = a;
5 ??printf( " %d?%d? " ??,( * ptr)[ 1 ],?( * ptr)[ 2 ]?);
6 ?? ++ ptr;
7 ??printf( " %d?%d " ??,( * ptr)[ 1 ],?( * ptr)[ 2 ]?);
8 }

9
The output for this program is:

(a) 2 3 5 6
(b) 2 3 4 5
(c) 4 5 0 0
(d) None of the above

8. Consider following function

?1int?*f1(void)
?2{
?3??int?x?=10;
?4??return(&x);
?5}

?6
?7int?*f2(void)
?8{
?9??int*ptr;
10??*ptr?=10;
11??return?ptr;
12}

13
14int?*f3(void)
15{
16??int?*ptr;
17??ptr=(int*)?malloc(sizeof(int));
18??return?ptr;
19}

20
Which of the above three functions are likely to cause problem with pointers

(a) Only f3
(b) Only f1 and f3
(c) Only f1 and f2
(d) f1 , f2 ,f3

9. Consider the following program:

1main()
2{
3??int?i=3;
4??int?j;
5??j?=?sizeof(++i+?++i);
6??printf("i=%d?j=%d",?i?,j);
7}

8
The output for this program is:

(a) i=4 j=2
(b) i=3 j=2
(c) i=3 j=4
(d) i=3 j=6

10. Consider the following program:

?1void?f1(int?*,?int);?
?2void?f2(int?*,?int);?
?3void(*p[2])?(?int?*,?int);
?4main()
?5{
?6??int?a;
?7??int?b;
?8??p[0]?=?f1;
?9??p[1]?=?f2;
10??a=3;
11??b=5;
12??p[0](&a?,?b);
13??printf("%d\t?%d\t"?,?a?,b);
14??p[1](&a?,?b);
15??printf("%d\t?%d\t"?,?a?,b);
16}

17
18void?f1(?int*?p?,?int?q)
19{
20??int?tmp;
21??tmp?=*p;
22??*p?=?q;
23??q=?tmp;
24}

25
26void?f2(?int*?p?,?int?q)
27{
28??int?tmp;
29??tmp?=*p;
30??*p?=?q;
31??q=?tmp;
32}
??
33
The output for this program is:

(a) 5 5 5 5
(b) 3 5 3 5
(c) 5 3 5 3
(d) 3 3 3 3

11. Consider the following program:

?1void?e(int?);???
?2main()
?3{
?4??int?a;
?5??a=3;
?6??e(a);
?7}

?8
?9void?e(int?n)
10{
11??if(n>0)
12??{
13????e(--n);
14????printf("%d"?,?n);
15????e(--n);
16??}

17}

18
19

The output for this program is:

(a) 0 1 2 0
(b) 0 1 2 1
(c) 1 2 0 1
(d) 0 2 1 1

12. Consider following declaration

1 typedef? int ?( * test)?(? float ? * ?,? float * )
2 test?tmp;
3

type of tmp is

(a) Pointer to function of having two arguments that is pointer to float
(b) int
(c) Pointer to function having two argument that is pointer to float and return int
(d) None of the above

13. Consider the following program:

1 main()
2 {
3 ?? char ? * p;
4 ?? char ?buf[ 10 ]? = {? 1 , 2 , 3 , 4 , 5 , 6 , 9 , 8 } ;
5 ??p? = ?(buf + 1 )[ 5 ];
6 ??printf( " %d " ?,?p);
7 }

8
The output for this program is:

(a) 5
(b) 6
(c) 9
(d) None of the above

14. Consider the following program:

?1Void?f(char**);
?2main()
?3{
?4??char?*?argv[]?={?"ab"?,"cd"?,?"ef"?,"gh",?"ij"?,"kl"?};
?5??f(?argv?);
?6}

?7
?8void?f(?char?**p?)
?9{
10??char*?t;
11??t=?(p+=?sizeof(int))[-1];
12??printf(?"%s"?,?t);
13}

14
The output for this program is:

(a) ab
(b) cd
(c) ef
(d) gh

15. Consider the following program:

?1#include<stdarg.h>
?2int?ripple?(?int?,?);
?3main()
?4{
?5??int?num;
?6??num?=?ripple?(?3,?5,7);
?7??printf(?"?%d"?,?num);
?8}

?9
10int?ripple?(int?n,?)
11{
12??int?i?,?j;
13??int?k;??
14??va_list?p;
15??k=?0;
16??j?=?1;
17??va_start(?p?,?n);?????
18??for?(;?j<n;??++j)?
19??{
20????i?=??va_arg(?p?,?int);
21????for?(;?i;????i?&=i-1??)
22??????++k;
23??}

24??return?k;
25}

26
27
The output for this program is:

(a) 7
(b) 6
(c) 5
(d) 3

16. Consider the following program:

?1int?counter?(int?i)
?2{
?3??static?int?count?=0;
?4??count?=?count?+i;
?5??return?(count?);
?6}

?7
?8main()
?9{
10??int?i?,?j;
11??for?(i=0;?i?<=5;?i++)
12????j?=?counter(i);
13}

14

The value of j at the end of the execution of the this program is:

(a) 10
(b) 15
(c) 6
(d) 7

?

Answer With Detailed Explanation

_____________________________________________________________

Answer 1.

The answer is (b)

volatile variable isn't affected by the optimization. Its value after the longjump is the last value variable assumed.

b last value is 5 hence 5 is printed.

setjmp : Sets up for nonlocal goto /* setjmp.h*/

Stores context information such as register values so that the lomgjmp function can return control to the statement following the one calling setjmp.Returns 0 when it is initially called.

Lonjjmp: longjmp Performs nonlocal goto /* setjmp.h*/

Transfers control to the statement where the call to setjmp (which initialized buf) was made. Execution continues at this point as if longjmp cannot return the value 0.A nonvolatile automatic variable might be changed by a call to longjmp.When you use setjmp and longjmp, the only automatic variables guaranteed to remain valid are those declared volatile.

Note: Test program without volatile qualifier (result may very)

Answer 2.

The answer is (a)

The members of structures have address in increasing order of their declaration. If a pointer to a structure is cast to the type of a pointer to its first member, the result refers to the first member.

Answer 3.

The answer is (a)

Non recursive version of the program

?1 int ??what?(? int ?x?,? int ??n)
?2 {
?3 ?? int ?val;
?4 ?? int ?product;
?5 ??product? = 1 ;
?6 ??val? = x;
?7 ?? while (n > 0 )
?8 ?? {
?9 ???? if ?(n % 2 ? == ? 1 )??
10 ??????product? = ?product * val;
11 ????n? = ?n / 2 ;?
12 ????val? = ?val * ?val;
13 ??}

14 }

15



/* Code raise a number (x) to a large power (n) using binary doubling strategy */
Algorithm description

1 ( while ?n > 0 )??
2 {
3 ?? if ??next?most?significant?binary?digit?of??n(?power)?? is ?one
4 ??then?multiply?accumulated?product?by?current?val??,?
5 ??reduce?n(power)??sequence?by?a?factor?of?two? using ?integer?division?.
6 ?? get ?next?val?by?multiply?current?value?of?itself???????????????????
7 }

8



Answer 4.

The answer is (c)

type of a is array of int
type of &a is pointer to array of int
Taking a pointer to the element one beyond the end of an array is sure to work.

Answer 5.

The answer is (b)

Answer 6.

The answer is (c)

The comma separates the elements of a function argument list. The comma is also used as an operator in comma expressions. Mixing the two uses of comma is legal, but you must use parentheses to distinguish them. the left operand E1 is evaluated as a void expression, then E2 is evaluated to give the result and type of the comma expression. By recursion, the expression

E1, E2, ..., En

results in the left-to-right evaluation of each Ei, with the value and type of En giving the result of the whole expression.

1 c = a,b;?? / ? * yields?c = a * ? /
2 d = (a,b);? /* ?d?=b?? */
3



Answer 7.

The answer is (a)


/* ptr is pointer to array of 3 int */

Answer 8.

The answer is (c)

f1 and f2 return address of local variable ,when function exit local variable disappeared

Answer 9.

The answer is (c)

sizeof operator gives the number of bytes required to store an object of the type of its operand . The operands is either an expression, which is not evaluated ( (++i + ++ i ) is not evaluated so i remain 3 and j is sizeof int that is 2) or a parenthesized type name.

Answer 10.

The answer is (a)

1 void ( * p[ 2 ])?(? int ? * ,? int );?



define array of pointer to function accept two argument that is pointer to int and return int. p[0] = f1; p[1] = f2 contain address of function .function name without parenthesis represent address of function Value and address of variable is passed to function only argument that is effected is a (address is passed). Because of call by value f1, f2 can not effect b

Answer 11.

The answer is (a)

Answer 12.

The answer is (c)

C provide a facility called typedef for creating new data type names, for example declaration

1 typedef? char ? string



Makes the name string a synonym for int .The type string can be used in declaration, cast, etc, exactly the same way that the type int can be. Notice that the type being declared in a typedef appears in the position of a variable name not after the word typedef.

Answer 13.

The answer is (c)

If the type of an expression is "array of T" for some type T, then the value of the expression is a pointer to the first object in the array, and the type of the expression is altered to "pointer to T"
So (buf+1)[5] is equvalent to *(buf +6) or buf[6]

Answer 14.

The answer is (d)

p+=sizeof(int) point to argv[2]

(p+=sizeof(int))[-1] points to argv[1]

Answer 15.

The answer is (c)

When we call ripple value of the first argument passed to ripple is collected in the n that is 3. va_start initialize p to point to first unnamed argument that is 5 (first argument).Each call of va_arg return an argument and step p to the next argument. va_arg uses a type name to determine what type to return and how big a step to take Consider inner loop

1 (;?i;?i &= i - 1 )?k ++ ? /* ?count?number?of??1?bit?in?i?*



in five number of 1 bits is (101) 2
i
n seven number of 1 bits is (111) 3
hence k return 5

example

1 let??i = ? 9 ? = ? 1001
2 ?????i - 1 ?? = ? 1000 ????????
3 ????(i - 1 )? + 1 ? = ?i
4 ??????????????? 1000
5 ????????????????? + 1
6 ?????????????? 1 ? 001



The right most 1 bit of i has corresponding 0 bit in i-1 this way i & i-1, in a two complement number system will delete the right most 1 bit I(repeat until I become 0 gives number of 1 bits)

Answer 16.

The answer is (b)

Static variable count remain in existence rather than coming and going each time function is called
so first call counter(0) count =0
second call counter(1) count = 0+1;
third call counter(2) count = 1+2; /* count = count +i */
fourth call counter(3) count = 3+3;
fifth call counter(4) count = 6+4;
sixth call counter(5) count = 10+5;
?

posted on 2006-11-01 12:02 編程之道 閱讀(402) 評論(0)  編輯 收藏 引用 所屬分類: C/C++

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲淫性视频| 欧美母乳在线| 欧美成人嫩草网站| 欧美成人精品一区二区| 免费看成人av| 亚洲电影免费观看高清完整版在线| 午夜精品久久久久久| 亚洲欧美国产精品va在线观看| 亚洲欧美综合另类中字| 亚洲午夜久久久久久久久电影院 | 欧美va天堂| 欧美黄污视频| 亚洲日本欧美天堂| 99日韩精品| 亚洲欧美日韩网| 久久亚洲国产精品日日av夜夜| 欧美第一黄色网| 欧美无乱码久久久免费午夜一区| 国产精品久久久久久久浪潮网站| 国产一区亚洲| 亚洲精品一二| 欧美主播一区二区三区| 欧美国产综合视频| 亚洲欧美日韩国产成人| 欧美激情综合在线| 韩国精品久久久999| 一本大道久久a久久综合婷婷| 久久av在线| 亚洲美女在线国产| 久久久久高清| 国产欧美日韩综合一区在线观看 | 欧美久久影院| 国产亚洲欧美一区二区| 99精品视频免费全部在线| 欧美一区网站| 亚洲精品一区久久久久久 | 国产精品福利在线观看| 亚洲国产精品t66y| 久久国产精品一区二区三区四区| 亚洲激情二区| 老司机一区二区| 国模一区二区三区| 欧美一区免费视频| 亚洲自拍偷拍色片视频| 欧美日韩一区视频| 99re热精品| 91久久国产综合久久| 久热成人在线视频| 在线精品视频在线观看高清| 久久久精品国产免费观看同学 | 女同性一区二区三区人了人一| 午夜精品影院| 国产精品乱码一区二三区小蝌蚪| 夜夜夜精品看看| 亚洲精品欧美极品| 欧美女同在线视频| 一区二区三区高清| 亚洲精品中文字幕在线观看| 欧美激情精品久久久| 亚洲精品免费网站| 亚洲精品乱码久久久久久黑人 | 欧美激情综合色综合啪啪| 欧美日韩另类国产亚洲欧美一级| 亚洲福利一区| 亚洲国产日韩欧美| 欧美日韩午夜在线| 久久综合一区二区三区| 欧美午夜不卡在线观看免费 | 欧美人与性动交a欧美精品| 久久av资源网站| 乱人伦精品视频在线观看| 亚洲女优在线| 国产日韩欧美电影在线观看| 亚洲精品一级| 一本大道久久精品懂色aⅴ| 欧美高清在线一区| 亚洲免费精彩视频| 欧美亚洲视频在线看网址| 国产精品电影网站| 亚洲天堂免费在线观看视频| 欧美专区第一页| 国外成人性视频| 欧美精品在线观看91| 亚洲图片欧美日产| 欧美一区二区三区婷婷月色 | 亚洲国产一区二区三区在线播 | 国产日韩精品一区观看| 亚洲国产精品久久久久秋霞影院 | av72成人在线| 欧美一区二区三区在线免费观看| 国产午夜精品美女毛片视频| 久久一区免费| 老司机成人在线视频| 国产精品色网| 亚欧美中日韩视频| 99在线精品视频在线观看| 久久精品道一区二区三区| 最新成人av在线| 国产日韩欧美精品一区| 亚洲一区图片| 亚洲人人精品| 亚洲黑丝在线| 激情久久久久久| 国产欧美日韩三级| 欧美性片在线观看| 欧美日韩精品二区第二页| 久热精品在线| 老司机午夜精品视频| 欧美综合国产精品久久丁香| 亚洲性色视频| 亚洲香蕉网站| 亚洲欧美色婷婷| 亚洲欧美日韩在线观看a三区| 夜夜躁日日躁狠狠久久88av| 亚洲精品色婷婷福利天堂| 欧美三级第一页| 国产精品人成在线观看免费 | 欧美激情精品久久久久久免费印度 | 欧美激情精品久久久六区热门| 久久夜精品va视频免费观看| 久久久久久夜| 欧美噜噜久久久xxx| 国产欧美日韩精品a在线观看| 99re热这里只有精品视频| 亚洲精品综合精品自拍| 米奇777在线欧美播放| 欧美成人午夜77777| 欧美日韩日本国产亚洲在线 | 国产精品久久久久久久免费软件| 欧美性理论片在线观看片免费| 黄色一区二区在线观看| 亚洲国内高清视频| 免费在线观看精品| 亚洲欧美国产va在线影院| 国产精品一区二区久久| 亚洲一区二区三区在线看| 亚洲高清资源| 欧美精品在线一区二区| 亚洲国产一区二区三区青草影视| 久久久久久久综合| 欧美高清不卡| 免费成人黄色| 亚洲一区二区三区高清| 午夜精品视频在线观看一区二区| 欧美精品粉嫩高潮一区二区| 一区二区在线视频播放| 久久久91精品国产一区二区三区 | 国产精品尤物| 亚洲综合首页| 亚洲天堂男人| 国产一在线精品一区在线观看| 久久国产免费看| 欧美不卡激情三级在线观看| 亚洲欧洲日夜超级视频| 最新国产成人av网站网址麻豆| 嫩草伊人久久精品少妇av杨幂| 日韩亚洲精品在线| 宅男噜噜噜66国产日韩在线观看| 国产乱人伦精品一区二区| 久久频这里精品99香蕉| 欧美另类在线播放| 久久精品视频免费播放| 欧美精品一二三| 欧美资源在线观看| 欧美激情麻豆| 蜜臀久久99精品久久久久久9 | 欧美一区二区三区视频在线 | 欧美激情精品久久久久久黑人| 99精品免费| 免播放器亚洲一区| 久久精品综合网| 欧美激情1区2区| 老司机午夜精品| 国产精品久久久久久久久婷婷| 欧美成人有码| 伊人久久大香线蕉综合热线| 亚洲欧美色婷婷| 亚洲女同同性videoxma| 老牛影视一区二区三区| 久久久久女教师免费一区| 国产精品一卡二| 亚洲一区二区三区国产| 亚洲免费伊人电影在线观看av| 欧美成人免费网站| 亚洲电影毛片| 亚洲伊人久久综合| 久久成人亚洲| 韩国欧美国产1区| 欧美三区在线| 亚洲美女在线视频| 欧美国产日韩精品免费观看| 中文在线资源观看网站视频免费不卡| 欧美电影电视剧在线观看| 国产精品99久久99久久久二8| 久久狠狠婷婷| 香蕉成人啪国产精品视频综合网| 黄色亚洲免费| 国产精品老牛| 欧美日韩综合一区| 久久一区二区三区四区|