What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { public: int x; }; class B : public A { public: B() { x=1;} B(int x) {this?>x = x;} }; int main () { B c1; B c2(10); cout << c1.x; cout << c2.x; return 0; }
Answer(s): B
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; void fun(char*); int main() { char t[4]={'0', '1', '2', '3'}; fun(&t[2]); return 0; } void fun(char *a) { cout << *a; }
Answer(s): A
What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { public: A() { cout << "A no parameters";} A(string s) { cout << "A string parameter";} A(A &a) { cout << "A object A parameter";} }; class B : public A { public: B() { cout << "B no parameters";} B(string s) { cout << "B string parameter";} }; int main () { A a2("Test"); B b1("Alan"); B b2(b1); return 0; }
What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { public: string s; A(string s) { this?>s = s; } }; class B { public: string s; B (A a) { this?>s = a.s; } void print() { cout<<s; } }; int main() { A a("Hello world"); B b=a; b.print(); }
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int op(int x, int y); int main() { float *pf; float f=0.9; pf=&f; cout << op(1, *pf); return 0; } int op(int x, int y) { return x*y; }
Post your Comments and Discuss C++ Institute CPA exam prep with other Community members: