大连亿达信息技术有限公司 vc++/c++ pg/se笔试题
选择题
1:下列各语句定义了数组,其中一个不正确的是
2:设int x[] = {1,2,3,4,5,6},* p = x;则值为3的表达式是
3:执行语句for(i=1;i++<4);后i的值是
4:union ty
{ int a;
int b;
} ;
main()
{ union ty t;
t.a=5;
t.b=4;
printf( “ %d,%d ” ,t,a,t,b);
}运行结果为
{ int a;
int b;
} ;
main()
{ union ty t;
t.a=5;
t.b=4;
printf( “ %d,%d ” ,t,a,t,b);
}运行结果为
5:执行下列语句
int a=8,b=7,c=6;
if(ac){a=c;c=b;}
printf(″%d,%d,%d\n″,a,b,c);
后输出的结果是
int a=8,b=7,c=6;
if(ac){a=c;c=b;}
printf(″%d,%d,%d\n″,a,b,c);
后输出的结果是
6:设函数定义如下:
float f1 (float a, float b)
{
return (a+b);
}
若有float x=1.1, y=2.2;,则以下语句中正确的函数调用是
float f1 (float a, float b)
{
return (a+b);
}
若有float x=1.1, y=2.2;,则以下语句中正确的函数调用是
7:执行语句“ for(s=0,i=1;i<=10;i=i+3) s+=i; ”后,变量 s 、 i 的当前值是
8:下列各语句中,能够且仅输出整型变量 a 、 b 中最大值的是
9:设 int a=9,b=20 ;则 printf( ″ %d,%d\n ″ ,a--,--b) ;的输出结果是
10:对于do-while语句,错误的说法是
11:初始化一维数组 a 正确的语句是
12:
- 执行下列程序
- #define R 0.5
- #define AREAx R*x*x
- main
- {int a=1, b=2;
- printf ″%5。1f\n″, AREAa+b;
- }
- 后输出的结果是
13:设 float c,f;, 将数学表达式 C= (F-32) 能正确表示成 C 语言赋值表达式的是
14:若数组名作实参而指针变量作形参,函数调用实参传给形参的是
简答题
15:以下两条输出语句分别输出什么?
float a = 1.0f;
cout << (int)a << endl;
cout << (int&)a << endl;
cout << boolalpha << ( (int)a == (int&)a ) << endl; // 输出什么?
Float b = 0.0f;
cout << (int)b << endl;
cout << (int&)b << endl;
cout << boolalpha << ( (int)b == (int&)b ) << endl; // 输出什么?
float a = 1.0f;
cout << (int)a << endl;
cout << (int&)a << endl;
cout << boolalpha << ( (int)a == (int&)a ) << endl; // 输出什么?
Float b = 0.0f;
cout << (int)b << endl;
cout << (int&)b << endl;
cout << boolalpha << ( (int)b == (int&)b ) << endl; // 输出什么?
16:阅读下列程序段,简述其主要功能。
#include
void main()
{
FILE*fpd1, *fpd2;
char ch;
fpd1=fopen(“d1.dat”,“r”) ;
fpd2=fopen(“d2.dat”,“w”) ;
while(fscanf(fpd1,“%c”,&ch)!=EOF)
if (ch>='A'&& ch <='Z' ‖ ch>='a'&& ch<='z')
fprintf(fpd2,“%c”,ch);
fclose(fpd1);
fclose(fpd);
}
#include
void main()
{
FILE*fpd1, *fpd2;
char ch;
fpd1=fopen(“d1.dat”,“r”) ;
fpd2=fopen(“d2.dat”,“w”) ;
while(fscanf(fpd1,“%c”,&ch)!=EOF)
if (ch>='A'&& ch <='Z' ‖ ch>='a'&& ch<='z')
fprintf(fpd2,“%c”,ch);
fclose(fpd1);
fclose(fpd);
}
17:根据蒙特卡洛算法计算圆周率
double PI( DOWRD dwCount/*测试次数*/ );
返回值:PI
double PI( DOWRD dwCount/*测试次数*/ );
返回值:PI
18:简述数组与指针的区别?
19:阅读下列程序,简述其主要功能。
# include
struct {
int hour, minute, second;
}time;
main ()
{
scanf (“%d:%d:%d” ,&time.hour, &time.minute, &time.second);
time.second++;
if (time.second ==60)
{
time.minute++
time.second=0;
if (time.minute==60)
{
time.hour++;
time.minute=0;
if (time.hour ==24) time.hour=0;
}
}
printf ( “ %d:%d:%d \ n ” , time.hour, time.minute, time.second);
}
# include
struct {
int hour, minute, second;
}time;
main ()
{
scanf (“%d:%d:%d” ,&time.hour, &time.minute, &time.second);
time.second++;
if (time.second ==60)
{
time.minute++
time.second=0;
if (time.minute==60)
{
time.hour++;
time.minute=0;
if (time.hour ==24) time.hour=0;
}
}
printf ( “ %d:%d:%d \ n ” , time.hour, time.minute, time.second);
}
20:用<<,>>,|,&实现一个WORD(2个字节)的高低位交换!!
21:编写子函数:(1)用冒泡法将一个数组排成升序的函数---SUB1;(2)在升序数组中插入一个数,并且保持该数组仍为升序数组的函数---SUB2。主函数:①输入任意10个正整数给数组;②调用SUB1对数组进行排序;③从键盘输入一个正整数,调用SUB2将其插入该数组。
22:请问以下代码有什么问题:
int main()
{
char a;
char *str=&a;
strcpy(str,"hello");
printf(str);
return 0;
}
int main()
{
char a;
char *str=&a;
strcpy(str,"hello");
printf(str);
return 0;
}
23: Write a program that prints a list of all words in a document, and, for each word, a list of the line numbers on which it occurs. Remove noise words like "the", "and," and so on.
24:int func(int a)
{
int b;
switch(a)
{
case 1: 30;
case 2: 20;
case 3: 16;
default: 0
}
return b;
}
则func(1)=?
{
int b;
switch(a)
{
case 1: 30;
case 2: 20;
case 3: 16;
default: 0
}
return b;
}
则func(1)=?
25:字符指针、浮点数指针、以及函数指针这三种类型的变量哪个占用的内存最大?为什么?