1.写出输出内容:
#include <iostream.h>
int main(){
int x = 2,y,z;
x *= (y=z=5);cout << x <<endl;
z = 3;
x == (y=2);cout << x <<endl;
x = (y == z); cout << x <<endl;
x = (y & z);cout << x <<endl;
x = (y && z);cout << x <<endl;
y = 4;
x = (y | z);cout << x <<endl;
x = (y || z);cout << x <<endl;
return 0;
}
输出 10 10 0 2 1 7 1 (忽略endl)
2.写出输出内容:
int i = 2, j = 3 ;
k = i +++ j;
cout <<k<<endl;
输出5 相当于k = (i ++) + j
3.比较效率:
(1) x = x + 1;
(2) x += 1;
(3) x ++;
答:(1)最低,因为要先要读右边的x,再x + 1,再读左边的x(编译器并不认为左右的x地址相同),再把右边的值赋给左边的值。
(2)其次,要先读出x,然后x+1,再将值赋给x。(只读了一次x)
(3)最高,读出x,再自增1。
4.输出结果:
#include <iostream.h>
#define product(x) (x*x)
int main()
{
int i=3,j,k;
j = product(i++);
k = product(++i);
cout << j <<","<< k << endl;
}
输出9,49
5.输出结果
如果int a= 4, b = 3;
那么,在执行完!a&&b++后,a,b的值分别为多少?
答:4,3 (!a为0,不会再计算b++)