What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int op(int x, int y) { return x?y; } int op(int x, float y) { return x+y; } int main() { int i=1, j=2, k, l; float f=0.23; k = op(i, j); l = op(j, f); cout<< k << "," << l; return 0; }
Answer(s): C
Which of the following statements are correct?
Answer(s): B,C
Which code, inserted at line 15, generates the output "5 Bob"? #include <iostream> #include <string> using namespace std; class B; class A { int age; public: A () { age=5; }; friend void Print(A &ob, B &so); }; class B { string name; public: B () { name="Bob"; }; //insert code here }; void Print(A &ob, B &so) { cout<<ob.age << " " << so.name; } int main () { A a; B b; Print(a,b); return 0; }
Answer(s): B
What is the output of the program if characters 't', 'e', 's' and 't' enter are supplied as input? #include <iostream> #include <string> using namespace std; int main() { string s; getline( cin, s ); cout << s << " " << s.length(); return( 0 ); }
Answer(s): A
What happens if character 3 is entered as input? #include <iostream> using namespace std; class A { public: int i; }; int main () { int c; A obj; obj.i = 5; cin >> c; try { switch (c) { case A. throw 20; case B. throw 5.2f; case C. throw obj; default: cout<<"No exception"; } } catch (int e) { cout << "int exception. Exception Nr. " << e; } catch (A e) { cout << "object exception. Exception Nr. " << e.i; } catch (...) { cout << "An exception occurred."; } 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.