整个测试遵循以下的约定:
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: 数据挖掘实验室
#include<setjmp.h>
static jmp_buf buf; 数据挖掘论坛
数据挖掘研究院
数据挖掘工具
main()
数据挖掘论坛
{
数据挖掘研究院
volatile int b;
b =3;
数据挖掘实验室
数据挖掘工具
数据挖掘工具
if(setjmp(buf)!=0)
数据挖掘交友
{
printf("%d ", b); 数据挖掘实验室
exit(0);
} 数据挖掘研究院
b=5; 数据挖掘工具
longjmp(buf , 1);
} 数据挖掘研究院
The output for this program is:
(a) 3
(b) 5
(c) 0
(d) None of the above 数据挖掘论坛
2. Consider the following program: 数据挖掘实验室
main() 数据挖掘研究院
{
struct node
数据挖掘工具
{ 数据挖掘交友
int a; 数据挖掘实验室
int b; 数据挖掘工具
int c; 数据挖掘论坛
}; 数据挖掘论坛
struct node s= { 3, 5,6 };
struct node *pt = &s; 数据挖掘研究院
printf("%d" , *(int*)pt);
}
The output for this program is:
(a) 3
(b) 5
(c) 6
(d) 7
数据挖掘研究院
3. Consider the following code segment:
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 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:
数据挖掘工具
main() 数据挖掘工具
{
int a[5] = {1,2,3,4,5}; 数据挖掘工具
int *ptr = (int*)(&a+1);
数据挖掘实验室
数据挖掘实验室
数据挖掘研究院
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 above 数据挖掘研究院
5. Consider the following program: 数据挖掘研究院
void foo(int [][3] ); 数据挖掘论坛
数据挖掘研究院
数据挖掘工具
main() 数据挖掘实验室
{ 数据挖掘研究院
int a [3][3]= { { 1,2,3} , { 4,5,6},{7,8,9}};
foo(a);
printf("%d" , a[2][1]);
数据挖掘实验室
}
数据挖掘实验室
数据挖掘工具
void foo( int b[][3])
{
++ b;
数据挖掘工具
b[1][1] =9;
数据挖掘交友
}
数据挖掘研究院
The output for this program is:
(a) 8
(b) 9
(c) 7
(d) None of the above
6. Consider the following program:
数据挖掘交友
main()
数据挖掘交友
{
数据挖掘实验室
int a, b,c, d; 数据挖掘工具
a=3; 数据挖掘实验室
b=5; 数据挖掘论坛
c=a,b; 数据挖掘交友
d=(a,b);
数据挖掘论坛
数据挖掘研究院
printf("c=%d" ,c); 数据挖掘工具
printf("d=%d" ,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=5
数据挖掘工具
7. Consider the following program: 数据挖掘实验室
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] );
} 数据挖掘论坛
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
数据挖掘论坛
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)); 数据挖掘研究院