| Exam Code/Number: | CPAJoin the discussion |
| Exam Name: | C++ Certified Associate Programmer |
| Certification: | C++ Institute |
| Question Number: | 220 |
| Publish Date: | May 25, 2026 |
|
Rating
100%
|
|
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;
class First
{
public:
First() { cout << "Constructor";}
void Print(){ cout<<"from First";}
};
int main()
{
First FirstObject;
FirstObject.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()
{
int i=2, j=2, k;
float f=0.3;
k = op(i, j);
cout<< k << "," << op(1, f);
return 0;
}
int op(int x, int y)
{
return x+y;
}
What happens when you attempt to compile and run the following code?
#include <iostream> #include <string> using namespace std;
class B;
class A { int age; public: A () { age=5; }; friend class B; };
class B { string name;
public:
B () { name="Bob"; };
void Print(A ob) {
cout << name << ob.age;
}
};
int main () {
A a;
B b;
b.Print(a);
return 0;
}
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 );
}