c語(yǔ)言高級(jí)面試題_第1頁(yè)
c語(yǔ)言高級(jí)面試題_第2頁(yè)
c語(yǔ)言高級(jí)面試題_第3頁(yè)
已閱讀5頁(yè),還剩16頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、整個(gè)測(cè)試遵循以下的約定:?假定在所有的程序中必須的頭文件都已經(jīng)被正確包含考慮如下的數(shù)據(jù)類型:?char 為 1 個(gè)字節(jié)?int 為 4 個(gè)字節(jié)?long int 為 4 個(gè)字節(jié)?float 為 4 個(gè)字節(jié)? double為個(gè)8字節(jié)? long double為8個(gè)字節(jié)?指針為 4 個(gè)字節(jié)1. Consider the following program:#include<setjmp.h>static jmp_buf buf;main()(volatile int b;b =3;if(setjmp(buf)!=0)printf("%d ", b);exit(0);

2、b=5;longjmp(buf , 1);The output for this program is:(a) 3(b) 5(c) 0(d) None of the above2. Consider the following program:main()(struct node(int a;int b;int c;;struct node s= ( 3, 5,6 ;struct node *pt = &s;*(int*)pt);printf(n%dnThe output for this program is:3(c)(d)5673. Con sider the follow ing

3、 code segme nt:int foo ( int x , int n)(int val;val =1;if (n>0)if (n%2 = 1) val = val *x;val = val夫 foo(x*x , n/2); return val;What fun cti on of x and n is compute by this code segme nt?(a) x n(b) x*n(c) n"x(d) None of the above4. Con sider the followi ng program:main()int a5int *ptr = (int

4、*)(&a+l);printf("%d %d" , * (a+1), * (ptr-1);The output for this program is:(a) 2 2(b) 2 1(c) 2 5(d) None of the above5. Consider the following program:void foo(int 3);main()int a 33= ( 1,2,3 , 4,5,6,;foo(a);printf("%d H , a21);+ b;bl 1 =9;The output for this program is:(a) 8(b) 9

5、(c) 7(d) None of the above6. Consider the following program:main()(int a, b,c, d;a=3;b=5;c=a,b;d=(a,b);printf( nc=%dn ,c);printf( nd=%dn ,d);)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=57. Consider the following program:main ()int a3 = ( 1,2,3 ,4,5,6;int (*ptr)3 =a;pri

6、ntf("%d %d " , (*ptr) 1, (*ptr) 2);+ptr;printf("%d %d ” , (*ptr) 1, (*ptr) 2);)The output for this program is:2 3 5 6)2 3 4 5/4 5 0 01 None of the above8. Consider following functionint *f1(void)int x =10;return(&x);int*ptr;*ptr =10;return ptr;int *f3(void)(int *ptr;ptr=(int*) mal

7、loc(sizeof(int);return ptr;Which of the above three functions are likely to cause problem with pointers(a)Onlyf3(b)Onlyflandf3(c)Onlyflandf2(d)fl ,f2, f39- Consider the following program:main()int i=3;int j;j = sizeof (+i+ +i); printf("i=%d j=%d", i ,j);The output for this program is:i=4j=

8、2(b) i=3j=2(c) i=3j=4(d) i=3j=610. Con sider the followi ng program:void fl (int *, int);void f2(int *, int);void(*p2) ( int夫, int);main()(int a;int b;p0 = fl;pl = f2;a=3;b=5;p0(&a , b);printf (*'%dt %dt" , a ,b);pl (&a , b);printf("%dt %dtn , a ,b);void fl( int* p , int q)int

9、tmp;tmp =*p;*P = q ; q= tmp;void f2( int* p , int q)int tmp;tmp =*p;*P = q ; q= tmp;The output for this program is:(b) 3535(c) 5353(d) 333311. Con sider the follow ing program:void e (int );main()int a;a=3;e (a);void e (int n)(if(n>0)e(-n);printf("%d n , n);e(-n);The output for this program

10、is:(b) 0 1 2 1(c) 12 0 1(d) 0 2 1 112. Con sider followi ng declarati ontypedef int (*test) ( float * , float*)test tmp;type of tmp is(a) Poi nter to fun cti on of hav ing two argume nts that is poin ter to float(b) int(c) Poin ter to fun cti on hav ing two argume nt that is poin ter to float and re

11、tur nint(d) None of the above13. Con sider the follow ing program:main()char *p;char buf10 =( 1,2,3,4,5,6,9,8;p = (buf+1)5;printf(n%(T , p);The output for this program is:5(b) 6(c) 9(d) None of the above14. Con sider the followi ng program:Void f(char*); main() void f( char *p )char* t;t= (p+= sizeo

12、f (int) -1;printf (n%sn , t);The output for this program is:(a) ab(b) cd(c) ef(d) gh15. Con sider the followi ng program:#include<stdarg.h> int ripple ( int ,.main ()int num;num = ripple ( 3, 5,7);printf( " %d" , num);int ripple (int n, .)int i , j;int k;va_list p;k= 0;j = 1 ;va_star

13、t( p , n);for (; j<n; +j)(i = va_arg( p , int);for (; i; i &=i-l ) +k;return k;The output for this program is:7)6/5J 316. Con sider the follow ing program:int counter (int i)static int count =0;count = count +i;return (count );)main()int i , j;for (i=0; i <=5; i+)j = counter(i);The value o

14、f j at the end of the execution of the this program is:(b) 15(c) 6(d) 7Answer With Detailed ExplanationAnswer 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

15、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 th

16、e 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

17、 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 re

18、fers to the first member.Answer 3.The answer is (a)Non recursive version of the programint what ( int x , int n)int val;int product;product =1;val =x;while(n>0)if (n%2 = 1)product = product*val;n = n/2;val = val* val;)/* Code raise a number (x) to a large power (n) using binary doubling strategy

19、*/ Algorithm description(while n>0)(if next most significant binary digit of n ( power) is onethen multiply accumulated product by current val ,reduce n(power) sequence by a factor of two using integer division .get next val by multiply current value of itselfAnswer 4.The answer is (c)type of a i

20、s array of inttype of &a is pointer to array of intTaking 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 expre

21、ssions. Mixing the two uses of comma is legal, but you must use parentheses to distinguish them, the left operand El is evaluated as a void expression, then E2 is evaluated to give the result and type of the comma expression. By recursion, the expressionEl, E2,. ? ,Enresults in the left-toright eval

22、uation of each Ei, with the value and type of En giving the result of the whole expression.c=a,b; /夫 yields c=a* /d= (a,b) ; /* d =b */Answer 7.The answer is (a)/* ptr is pointer to array of 3 int */Answer 8.The answer is (c)fl and f2 return address of local variable , when function exit local varia

23、ble disappearedAnswer 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 typ

24、e name.Answer 10.The answer is (a)void(*p2) ( int *, int); define array of pointer to function accept two argument that is pointer to int andnamereturn int. p0 = fl; pl = f2 contain address of function , function without parenthesis represent address of function Value and address of variable is pass

25、ed to function only argument that is effected is a (address is passed). Because of call by value fl, f2 can not effect bAnswer 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 typedef char stringMakes the nam

26、e 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 expre

27、ssion is/z array of T for some type T, then the value ofthe 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 buf6Answer 14.The answer is (d)p+=sizeof(int) point to argv2(p+=sizeof (int) T points to argvlAnswer 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).

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論