What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class A { public: void Print(){ cout<<"A";} }; class B:public A { public: virtual void Print(){ cout<< "B";} }; int main() { A *obj; A ob1; obj = &ob1; obj?>Print(); B ob2; obj = &ob2; obj?>Print(); }
Answer(s): B
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { const int x=0; const int *ptr; ptr = &x; cout<<*ptr; return 0; }
Answer(s): A
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int i = 1; for(i=10; i>-1; i/=2) { if(!i) break; } cout << i; return 0; }
What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; class A { public: int x; A() { x=0;} }; class B { public: int x; B() { x=1;} }; class C :public A, public B { public: int x; C(int x) { this?>x = x; A::x = x + 1; } void Print() { cout << x << A::x << B::x; } }; int main () { C c2(1); c2.Print(); return 0; }
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; namespace myNamespace1 { int x = 5; int y = 10; } namespace myNamespace2 { float x = 3.14; float y = 1.5; } int main () { { using namespace myNamespace1; cout << x << " "; }{ using namespace myNamespace2; cout << y; } 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.