第二章:
1、C++有哪几种数据类型?简述其值域。编程显示你使用的计算机中的各种数据类型的字节数。
答:
#includeint main() { cout<<"The size of an int is:\t\t"<
2、运行下面的程序,观察其输出,与你的设想是否相同?
#includeusing namespace std; int main() { unsigned int x; unsigned int y=100; unsigned int z=50; x=y-z; cout<<"Difference is: "< 答: 程序运行输出:
Difference is: 50
Now difference is:4294967246
注意,第二行的输出并非-50,注意x、y、z的数据类型。
3、若a=1,b=2,c=3,下列各式的结果是什么?
(1)a | b -c
(2)a ^ b & -c
(3)a & b | c
(4)a | b & c
答:
1、-1
2、1
3、3
4、3
解释:&、|、^:分别是与、或、异或运算符,还有取反~、移位(左移<<和右移>>)