What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { public: A() { cout << "A0 ";} A(string s) { cout << "A1";} }; class B : public A { public: B() { cout << "B0 ";} B(string s) { cout << "B1 ";} }; class C : private B { public: C() { cout << "C0 ";} C(string s) { cout << "C1 ";} }; int main () { B b1; C c1; return 0; }
Answer(s): C
What is the output of the program? #include <iostream> #include <string> using namespace std; struct Person { int age; }; class First { Person *person; public: First() {person = new Person; person?>age = 20; } void Print(){ cout << person?>age; } }; int main() { First t[2]; for (int i=0; i<2; i++) t[i].Print(); }
Answer(s): B
What happens when you attempt to compile and run the following code? #include <cstdlib> #include <iostream> using namespace std; inline float sum(float a,float b) { return a+b; } int main() { float a,b; a = 1.5; b = 3.4; cout<<sum(a,b); return 0; }
What is the output of the program? #include <iostream> #include <string> using namespace std; int main() { string s1="Hello"; string s2="World"; s1+=s2; cout << s1; return( 0 ); }
Answer(s): A
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; #define DEF_A 0 #define DEF_B DEF_A+1 #define DEF_C DEF_B+1 int main(int argc, char *argv[]) { cout << DEF_C; return 0; }
Post your Comments and Discuss C++ Institute CPA exam prep with other Community members:
Our website is free, but we have to fight against AI bots and content theft. We're sorry for the inconvenience caused by these security measures. You can access the rest of the CPA content, but please register or login to continue.