当前位置:文档之家› 带答案C语言2-10章作业

带答案C语言2-10章作业

C语言习题集专业班级
学姓号名
C语言习题集
第2章运算符与表达式
一、选择题
1.若有定义:int a=2,b=3 ; float x=3.5,y=
2.5;则下面表达式的值为( C )。

(float)(a+b)/2+(int)x% (int)y
A)3.5 B)35 C)3.500000 D)35.00000
2.若有定义:int x=3 ,y=2; float a=2.5 ,b=
3.5;则下面表达式的值
为( B )。

(x+y)%2+(int)a/(int)b
A)1.0 B)1 C)2.0 D)2
3.若x和n均是int型变量,且x的初值为12,n的初值为5,则执行下面表达式后x的值为( A )。

x%=(n%=2)
A)0 B)1 C)2 D)3
4.设有int x=11;则表达式(x++*1/3)的值是( A )。

A)3 B)4 C)11 D)12
5.下列程序的输出结果是( C
)。

#include <stdio.h>
main( )
{ double d=3.2; int x,y;
x=1.2; y=(x+3.8)/5.0;
printf("%d\n", d*y);}
A)3 B)3.2 C)0 D)3.07
6.下列程序执行后的输出结果是(小数点后只写一位)( A )。

#include <stdio.h>
main( )
{ double d; float f; long l; int i;
i=f=l=d=20/3;
printf("%d %ld %f %f\n", i,l,f,d);
}
A)6 6 6.0 6.0 B)6 6 6.7 6.7
C)6 6 6.0 6.7 D)6 6 6.7 6.0
7.若已定义x和y为double类型,则表达式x=1,y=x+3/2的值是( C )。

A)1 B)2 C)2.0 D)2.5
8.若变量a,i已正确定义,且i已正确赋值,则合法的语句是(
B )。

A)i=int(a) B)++i; C)a=a++=5; D)a=int(i);
9.若执行以下程序段后,c3的值为( A )。

int c1=1,c2=2,c3;
c3=1.0/c2*c1;
A)0 B)0.5 C)1 D)2
10.如下程序的运行结果是( D )。

#include <stdio.h>
main( )
{ int y=3,x=3,z=1;
printf("%d %d\n",(++x,y++),z+2);
}
第1页/34页
C语言习题集
A)3 4 B)4 2 C)4 3 D)3 3
11.能正确表示逻辑关系:“a≥10或a≤0”的C语言表达式是(
)。

D
C)a>=10
A)a>=10 or a<=0 B)a>=0|a<=10
&& a<=0 D)a>=10||a<=0
12.设x,y,t均为int型变量,则执行语句:x=y=3;t=++x||++y; 后,y的值为( C )。

A)不定值B)4 C)3 D)1
13.以下程序的输出结果是( D )。

#include <stdio.h>
main( )
{ int a=3;
printf("%d\n",(a+=a-=a*a));
}
A)-6 B)12 C)0 D)-12
14.设a,b,c,d,m,n均为int型变量,且
a=5,b=6,c=7,d=8,m=2,n=2,则逻辑表达式(m=a>b)& &(n=c>d)运算后,n的值为( C )。

A)0 B)1 C)2 D)3
15.在C语言中,如果下面的变量都是int类型,则输出的结果
是( A )。

sum=pad=5; pad=sum++,pad++,++pad;
printf(“%d\n”,pad);
A)7 B)6 C)5 D)4
二、填空题
1.若a,b和c均是int型变量,则执行表达式a=(b=4)+(c=2)后,a 值为__6____,b值为__4____,c值为__2____。

2.若a是int型变量,且a的初值为6,则执行表达式 a+=a-=a*a 后a的值为___-60___。

3.若a是int型变量,则执行表达式a=25/3%3后a的值为
___2___。

4.若x和n均是int型变量,且x和n的初值均为5,则执行表达式x+=n++后x的值为__10____,n的值为___6___。

5.表达式8/4*(int)2.5/(int)(1.25*(3.7+2.3))值的数据类型为__int 型___。

6.若a是int型变量,则表达式(a=4*5,a*2),a+6的值为__26____。

7.若x和a均是int型变量,则执行表达式x=(a=4,6*2)后x的值为__12__,执行表达式(x=a=4,6*2)后x的值为__4___。

8.若有以下定义int m=5,y=2;,则执行表达式y+=y-=m*=y后y的值是__-16____。

9.已知int y;float x=-3;,执行语句y=x%2;后,变量y的值为__语句本身是错误的_错误的赋值__。

10.若int w=1,x=2,y=3,z=4;则条件表达式w>x?w:y<z?y:z的结果为__3____。

11.以下程序的输出结果是__10
9____。

#include <stdio.h>
main( )
{ int x=10,y=10;
printf("%d %d\n",x--,--y);
}
12.表达式8.0*(1/2)的值为__0.0____。

第2页/34页
C语言习题集。

相关主题