这些题目,来测试一下你的C语言水平

1,The output for this program is: (a) 3 (b) 5 (c) 0
C/C++ code
#include<setjmp.h>

static jmp_buf buf;

int main() {
    volatile int b;
    b =3;

    if(setjmp(buf)!=0) {
        printf("%d ", b);
        exit(0);
    } 
    b=5;

    longjmp(buf , 1);

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

    return 0;
}

3,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
C/C++ code
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;
}

4,The output for this program is: (a) 2 2 (b) 2 1 (c) 2 5 (d) None of the above
C/C++ code
int main() {
    int a[5] = {1,2,3,4,5};
    int *ptr = (int*)(&a+1);
    printf("%d %d" , *(a+1), *(ptr-1) );
    return 0;
}

5,The output for this program is: (a) 8 (b) 9 (c) 7 (d) None of the above
C/C++ code
void foo(int [][3] ); 
int main(){ 
    int a [3][3]= { { 1,2,3} , { 4,5,6},{7,8,9}}; 
    foo(a); 
    printf("%d" , a[2][1]); 
    return 0;
} 

void foo( int b[][3]) { 
    ++ b; 
    b[1][1] =9; 
} 

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
C/C++ code
int main() { 
    int a, b,c, d; 
    a=3; 
    b=5; 
    c=a,b; 
    d=(a,b); 
    printf("c=%d" ,c); 
    printf("d=%d" ,d); 
    return 0;
} 

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
C/C++ code
int main() { 
    int a[][3] = { 1,2,3 ,4,5,6}; 
    int (*ptr)[3] =a; 
    printf("%d %d " ,(*ptr)[1], (*ptr)[2] ); 
    ++ptr; 
    printf("%d %d" ,(*ptr)[1], (*ptr)[2] ); 
    return 0;
} 

8,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
C/C++ code
int *f1(void) { 
    int x =10; 
    return(&x); 
} 
int *f2(void) { 
    int*ptr; 
    *ptr =10; 
    return ptr; 
} 
int *f3(void) { 
    int *ptr; 
    ptr=(int*) malloc(sizeof(int)); 
    return ptr; 
}

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
C/C++ code
int main() { 
    int i=3; 
    int j; 
    j = sizeof(++i+ ++i); 
    printf("i=%d j=%d", i ,j); 
    return 0;
}


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
C/C++ code
void f1(int *, int); 
void f2(int *, int); 
void(*p[2]) ( int *, int); 

int main() { 
    int a; 
    int b; 
    p[0] = f1; 
    p[1] = f2; 
    a=3; 
    b=5; 
    p[0](&a , b); 
    printf("%d\t %d\t" , a ,b); 
    p[1](&a , b); 
    printf("%d\t %d\t" , a ,b); 
    return 0;
} 

void f1( int* p , int q) { 
    int tmp;
    tmp =*p; 
    *p = q; 
    q= tmp; 
} 
void f2( int* p , int q) { 
    int tmp; 
    tmp =*p; 
    *p = q; 
    q= tmp; 
}

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
C/C++ code
void e(int ); 
int main() {
    int a; 
    a=3; 
    e(a); 
    return 0;
} 

void e(int n) { 
    if(n>0) { 
        e(--n); 
        printf("%d" , n); 
        e(--n); 
    } 
}

12,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
C/C++ code
typedef int (*test) ( float * , float*) 
test tmp;

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

14,The output for this program is: (a) ab (b) cd (c) ef (d) gh
C/C++ code
Void f(char**);
int main() { 
    char * argv[] = { "ab" ,"cd" , "ef" ,"gh", "ij" ,"kl" }; 
    f( argv );
     
    return 0;
} 
void f( char **p ) { 
    char* t; 
    t= (p+= sizeof(int))[-1]; 
    printf( "%s" , t);     
} 

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

int ripple (int n, ...) { 
    int i , j; 
    int k; 
    va_list p; 
    k= 0; 
    j = 1; 
    va_start( p , n); 
    for (; j<n; ++j) { 
        i = va_arg( p , int); 
        for (; i; i &=i-1 ) 
            ++k; 
    } 
    return k; 
} 

16, The value of j at the end of the execution of the this program is:
 (a) 10 (b) 15 (c) 6 (d) 7
C/C++ code
int counter (int i) { 
    static int count =0; 
    count = count +i; 
    return (count ); 
} 
int main() { 
    int i , j; 
    for (i=0; i <=5; i++) 
    j = counter(i); 
    return 0;
}

最后的答案分别是:

1.   B       2.  A     3.   A       4.  C    5.   B      6.  C     7.    A     8.         9. C    10.    A      11.  A       12.       


 13.  C     14.D    15.C       16.B

你可能感兴趣的:(c,测试,语言,float,output,Pointers)