阅读下列程序,写出运行结果。 #include [iostream] using namespace std; int main() { int a = 1, b = 2; bool x, y; cout [< (a++)+(++b) << endl; cout << a % b << endl; x = !a]b; y = a-- && b; cout << x << endl; cout << y << endl; }
举一反三
- 运行下列程序,第1行输出是____,第2行输出是____,第3行输出是____,第4行输出是____。 #include[iostream] using namespace std; class A{ int a; public: A( ){ a=1; cout<<a<<endl; } ~A(){ a--; cout<<a<<endl; } }; class B{ int b; A a1; public: B( ){ b=3; cout<<b<<endl; } ~B(){ b--; cout<<b<<endl; } }; int main( ) { B b; return 0; }
- 阅读以下程序,写出运行结果。 #include using namespace std; class Test { private: int num; public: Test(); Test(int n); }; Test::Test() { cout << "Init defa" << endl; num = 0; } Test::Test(int n) { cout << "Init" << " " << n << endl; num = n; } int main() { Test x[2]; Test y(15); return 0; }
- 运行下列程序,第1行输出是____,第2行输出是____,第3行输出是____。 #include[ iostream ] using namespace std; int a, b(1); int main( ) { int a=2; { int a=3; a+=10; b+=10; cout<<a+b<<endl; } a+=100; b+=100; cout<<a+b<<endl; cout<<::a+::b<<endl; return 0; }
- 1、写出下列程序的输出结果 #include [iostream] using namespace std; int b=2; int func(int *a) { b+=*a; return(b); } int main( ) { int a=2,res=2; res+=func(&a); cout<<res<<endl; return 0; }
- 有如下程序#include [iostream] using namespace std; int max(int x,int y) { int z; if(x>y) z=x; else z=y; return z; } int main() { int a=3,b=5; cout<<"max="<<max(a,b)<<endl; } A: max=3 B: max=4 C: max=5 D: max=6