中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > Windows编程
高级C语言程序员测试必过的十六道最佳题目+答案详解(1)
作者:佚名 时间:2007-12-10 17:15 出处:csdn 责编:月夜寒箫
              摘要:高级C语言程序员测试必过的十六道最佳题目+答案详解(1)

【引自dishening的博客】整个测试遵循以下的约定:
◆假定在所有的程序中必须的头文件都已经被正确包含。

考虑如下的数据类型:

◆char为1个字节
◆int为4个字节
◆long int为4个字节
◆float为4个字节
◆double为个8字节
◆long double为8个字节
◆指针为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));
return ptr;
}

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:

            

main()
{
int i=3;
int j;
j = sizeof(++i+ ++i);
printf("i=%d j=%d", i ,j);
}

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:

            

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

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:

            

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

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

            

typedef int (*test) ( float * , float*)
test tmp;

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:

            

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

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

14、Consider the following program:

            

Void f(char**);
main()
{
char * argv[] = { "ab" ,"cd" , "ef" ,"gh", "ij" ,"kl" };
f( argv );
}
void f( char **p )
{
char* t;
t= (p+= sizeof(int))[-1];
printf( "%s" , t);
}

The output for this program is:
(a) ab
(b) cd
(c) ef
(d) gh

15、Consider the following 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_start( p , n);    
for (; j<n;  ++j)
{
i =  va_arg( p , int);
for (; i;    i &=i-1  )
++k;
}
return k;
}

The output for this program is:
(a) 7
(b) 6
(c) 5
(d) 3

16、Consider the following 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 of j at the end of the execution of the this program is:
(a) 10
(b) 15
(c) 6
(d) 7

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有