4,变量说明的意义是什么? 下面的说明正确吗?
char c1,c2,c3=‘\0’; /*正确 */
int k1=k2=k3=0; /*错误,必须逐个赋初值 */
/* int k1=0,k2=0,k3=0; */
float x1=1; y=0;
double a=1e-5,b /*说明语句应以分号结尾 */
同时说明的变量用逗号分隔
6,设 i,j 是整型,a浮点,判断下列表达式是否正确:
(1) (17/15) %3 (正确 )
(2) a &0377 (正确 )
(3) (i%j) <<2 (正确 )
(4) --a (正确 )
(5) (i*j)++ (错误)
(6) i<j<a (语法正确、语义错误) i<j && j<a
(7) i=‘A’>=‘B’ (正确 )
(8) (a=i*j) >=0? a,-a (正确 )
(9) double(i+j) (错误 ) ( double) (i+j)
(10) i^j && a (正确 )
7 unsigned short i=013,j=0x13,k=0,a,b,c,d;
short e,f;
给出下列表达式的结果和类型:
结果 类型
(1) a=i==j 0 unsigned short
(2) i!=j 1 int
(3) !k 1 int
(4) b=!i 0 unsigned short
(5) i^j
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1
(5) i^j
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0
结果,24
类型,int
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1
(6) c=i | j
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1
结果,27 类型,unsigned short
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0
(7) d=~i
结果,65524 类型,unsigned short
(8) ~k
结果,-1 类型,unsigned int (16)
int (32)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0
(9) e=~i
结果,-12 类型,short
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
(10) f=~k
结果,-12 类型,short
(11) k++? i,j 结果,0x13 类型,unsigned int
(12) i++,j=i 结果,014 类型,unsigned int
8.int k=0,m,n;
(1) n=k++,m=(k*=2)
k,2
m,2
n,0
(2) n=0,--n,n+=(n++) –n
n,0
n=n+(n++) –n=-1+(-1)-(-1)= -1