What happens when you attempt to compile and run the following code?
#include
using namespace std;
class BaseClass
{
public:
int *ptr;
BaseClass(int i) { ptr = new int(i); }
~BaseClass() { delete ptr; delete ptr;}
void Print() { cout << *ptr; }
};
void fun(BaseClass x);
int main()
{
BaseClass o(10);
fun(o);
o.Print();
}
void fun(BaseClass x) {
cout << "Hello:";
}
A. It prints: Hello:1
B. It prints: Hello:
C. It prints: 10
D. Runtime error.
What is the output of the program?
#include
#include
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();
}
A. It prints: 10
B. It prints: 2020
C. It prints: 22
D. It prints: 00
What is the output of the program?
#include
#include
using namespace std;
int main () {
string s1 = "Hello", s2 = "World";
s2 = s1 + s2;
cout << s2;
return 0;
}
A. It prints: Hello
B. It prints: HelloWorld
C. It prints: WorldHello
D. It prints: WorldHelloWorld
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main (int argc, const char * argv[])
{
int a = 30, b = 1, c = 5, i=10;
i = b < a < c;
cout << i;
return 0;
}
A. compilation fails
B. It prints: 10
C. It prints: 0
D. It prints: 1
What happens when you attempt to compile and run the following code?
#include
#include
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;
}
A. It prints: Bob5
B. It prints: Bob
C. It prints: 5
D. None of these
What happens when you attempt to compile and run the following code?
#include
using namespace std;
void fun(int);
int main()
{
int a=0;
fun(a);
return 0;
}
void fun(int n)
{
if(n < 2)
{
fun(++n);
cout << n;
}
}
A. It prints: 21
B. It prints: 012
C. It prints: 0
D. None of these
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class A {
public :
void print() {
cout << "A ";
}
};
class B {
void print() {
cout << "B ";
}
};
int main() {
B sc[2];
A *bc = (A*)sc;
for (int i=0; i<2;i++)
(bc++)->print();
return 0;
}
A. It prints: A A
B. It prints: B B
C. It prints: A B
D. It prints: B A
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main(){
int i = 1;
if (--i==1) {
cout << i;
} else {
cout << i-1;
}
return 0;
}
A. It prints: 0
B. It prints: 1
C. It prints: -1
D. It prints: 2
What is the output of the program if character 2 is supplied as input?
#include
using namespace std;
int main () {
int c;
cin >> c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (float e)
{ cout << "float exception. Exception Nr. " << e; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}
A. It prints: float exception. Exception Nr.
B. It prints: int exception. Exception Nr. 20
C. It prints: An exception occurred
D. It prints: float exception. Exception Nr. 5.2
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class complex{
double re, im;
complex() : re(1),im(0.4) {}
complex operator?(complex andt);
void Print() { cout << re << " " << im; }
};
complex complex::operator? (complex andt){
complex temp;
temp.re = this?>re ? t.re;
temp.im = this?>im ? t.im;
return temp;
}
int main(){
complex c1,c2,c3;
c3 = c1 ? c2;
c3.Print();
}
A. It prints: 1 0.4
B. It prints: 2 0.8
C. It prints: 0 0
D. It prints: 1 0.8
Nowadays, the certification exams become more and more important and required by more and more enterprises when applying for a job. But how to prepare for the exam effectively? How to prepare for the exam in a short time with less efforts? How to get a ideal result and how to find the most reliable resources? Here on Vcedump.com, you will find all the answers. Vcedump.com provide not only C++ Institute exam questions, answers and explanations but also complete assistance on your exam preparation and certification application. If you are confused on your CPA-21-02 exam preparations and C++ Institute certification application, do not hesitate to visit our Vcedump.com to find your solutions here.