滴水逆向联盟

标题: [推荐] 筒子们来测试下C语言的基础水平 [打印本页]

作者: 大灰狼    时间: 2014-5-26 13:56
标题: [推荐] 筒子们来测试下C语言的基础水平
1,The output for this program is: (a) 3 (b) 5 (c) 0
C/C++ code
  1. #include<setjmp.h>

  2. static jmp_buf buf;

  3. int main() {
  4.     volatile int b;
  5.     b =3;

  6.     if(setjmp(buf)!=0) {
  7.         printf("%d ", b);
  8.         exit(0);
  9.     }
  10.     b=5;

  11.     longjmp(buf , 1);

  12.     return 0;
  13. }
  14. 2,The output for this program is: (a) 3 (b) 5 (c) 6 (d) 7
  15. C/C++ code
  16. struct node { int a; int b; int c; };
  17. int main() {
  18.     struct node s= { 3, 5,6 };
  19.     struct node *pt = &s;
  20.     printf("%d" , *(int*)pt);

  21.     return 0;
  22. }
  23. 3,What function of x and n is compute by this code segment?
  24. (a) x^n (b) x*n (c) n^x (d) None of the above
  25. int foo ( int x , int n) {
  26.     int val;
  27.     val =1;
  28.     if (n>0) {
  29.         if (n%2 == 1) val = val *x;
  30.         val = val * foo(x*x , n/2);
  31.     }
  32.     return val;
  33. }

  34. 4,The output for this program is: (a) 2 2 (b) 2 1 (c) 2 5 (d) None of the above
  35. C/C++ code

  36. int main() {
  37.     int a[5] = {1,2,3,4,5};
  38.     int *ptr = (int*)(&a+1);
  39.     printf("%d %d" , *(a+1), *(ptr-1) );
  40.     return 0;
  41. }

  42. 5,The output for this program is: (a) 8 (b) 9 (c) 7 (d) None of the above
  43. C/C++ codevoid foo(int [][3] );
  44. int main(){
  45.     int a [3][3]= { { 1,2,3} , { 4,5,6},{7,8,9}};
  46.     foo(a);
  47.     printf("%d" , a[2][1]);
  48.     return 0;
  49. }

  50. void foo( int b[][3]) {
  51.     ++ b;
  52.     b[1][1] =9;
  53. }

  54. 6,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
  55. C/C++ codeint main() {
  56.     int a, b,c, d;
  57.     a=3;
  58.     b=5;
  59.     c=a,b;
  60.     d=(a,b);
  61.     printf("c=%d" ,c);
  62.     printf("d=%d" ,d);
  63.     return 0;
  64. }

  65. 7,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
  66. C/C++ codeint main() {
  67.     int a[][3] = { 1,2,3 ,4,5,6};
  68.     int (*ptr)[3] =a;
  69.     printf("%d %d " ,(*ptr)[1], (*ptr)[2] );
  70.     ++ptr;
  71.     printf("%d %d" ,(*ptr)[1], (*ptr)[2] );
  72.     return 0;
  73. }

  74. 8,Which of the above three functions are likely to cause problem with pointers
  75. (a) Only f3 (b) Only f1 and f3 (c) Only f1 and f2 (d) f1 , f2 ,f3
  76. C/C++ codeint *f1(void) {
  77.     int x =10;
  78.     return(&x);
  79. }
  80. int *f2(void) {
  81.     int*ptr;
  82.     *ptr =10;
  83.     return ptr;
  84. }
  85. int *f3(void) {
  86.     int *ptr;
  87.     ptr=(int*) malloc(sizeof(int));
  88.     return ptr;
  89. }

  90. 9,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
  91. C/C++ code
  92. int main() {     int i=3;     int j;     j = sizeof(++i+ ++i);     printf("i=%d j=%d", i ,j);     return 0;}
  93. 10,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
  94. C/C++ code
  95. void f1(int *, int);
  96. void f2(int *, int);
  97. void(*p[2]) ( int *, int);

  98. int main() {
  99.     int a;
  100.     int b;
  101.     p[0] = f1;
  102.     p[1] = f2;
  103.     a=3;
  104.     b=5;
  105.     p[0](&a , b);
  106.     printf("%d\t %d\t" , a ,b);
  107.     p[1](&a , b);
  108.     printf("%d\t %d\t" , a ,b);
  109.     return 0;
  110. }

  111. void f1( int* p , int q) {
  112.     int tmp;
  113.     tmp =*p;
  114.     *p = q;
  115.     q= tmp;
  116. }
  117. void f2( int* p , int q) {
  118.     int tmp;
  119.     tmp =*p;
  120.     *p = q;
  121.     q= tmp;
  122. }

  123. 11,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
  124. C/C++ codevoid e(int );
  125. int main() {
  126.     int a;
  127.     a=3;
  128.     e(a);
  129.     return 0;
  130. }

  131. void e(int n) {
  132.     if(n>0) {
  133.         e(--n);
  134.         printf("%d" , n);
  135.         e(--n);
  136.     }
  137. }

  138. 12,type of tmp is (a) Pointer to function of having two arguments that is pointer to float
  139. (b) int
  140. (c) Pointer to function having two argument that is pointer to float and return int
  141. (d) None of the above
  142. C/C++ code
  143. typedef int (*test) ( float * , float*)
  144. test tmp;


  145. 13,The output for this program is: (a) 5 (b) 6 (c) 9 (d) None of the above
  146. C/C++ code
  147. int main() {
  148.     char *p;
  149.     char buf[10] ={ 1,2,3,4,5,6,9,8};
  150.     p = &((buf+1)[5]);
  151.     printf("%d" , *p);
  152.     return 0;
  153. }


  154. 14,The output for this program is: (a) ab (b) cd (c) ef (d) gh
  155. C/C++ code
  156. Void f(char**);
  157. int main() {
  158.     char * argv[] = { "ab" ,"cd" , "ef" ,"gh", "ij" ,"kl" };
  159.     f( argv );

  160.     return 0;
  161. }
  162. void f( char **p ) {
  163.     char* t;
  164.     t= (p+= sizeof(int))[-1];
  165.     printf( "%s" , t);     
  166. }


  167. 15,The output for this program is: (a) 7 (b) 6 (c) 5 (d) 3
  168. C/C++ code
  169. #include<stdarg.h>
  170. int ripple ( int , ...);
  171. int main(){
  172.     int num;
  173.     num = ripple ( 3, 5,7);
  174.     printf( " %d" , num);
  175.     return 0;
  176. }

  177. int ripple (int n, ...) {
  178.     int i , j;
  179.     int k;
  180.     va_list p;
  181.     k= 0;
  182.     j = 1;
  183.     va_start( p , n);
  184.     for (; j<n; ++j) {
  185.         i = va_arg( p , int);
  186.         for (; i; i &=i-1 )
  187.             ++k;
  188.     }
  189.     return k;
  190. }


  191. 16, The value of j at the end of the execution of the this program is:
  192. (a) 10 (b) 15 (c) 6 (d) 7
  193. C/C++ code
  194. int counter (int i) {
  195.     static int count =0;
  196.     count = count +i;
  197.     return (count );
  198. }
  199. int main() {
  200.     int i , j;
  201.     for (i=0; i <=5; i++)
  202.     j = counter(i);
  203.     return 0;
  204. }


复制代码









欢迎光临 滴水逆向联盟 (http://dtdebug.com/) Powered by Discuz! X3.2