Online Access Free CPA Practice Test

Exam Code:CPA
Exam Name:C++ Certified Associate Programmer
Certification Provider:C++ Institute
Free Question Number:220
Posted:Aug 08, 2022
Rating
100%

Question 1

Given:
#include <iostream>
#include <exception>
using namespace std;
int main () {
try
{
int * myarray= new int[1000];
}
catch (bad_alloc&)
{ cout << "Error allocating memory"; } catch (exception& e) { cout << "Standard exception"; } catch (...) { cout << "Unknown exception"; } return 0; }
What will happen if we use the operator "new" and the memory cannot be allocated?

Question 2

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
void setAge(int a=20) {age = a;}
void Print() { cout << age;}
};
int Base::age=0;
int main () {
Base a;
a.setAge(10);
a.Print();
a.setAge();
a.Print();
return 0;
}

Question 3

What will variable "y" be in class B?
class A { int x; protected: int y; public: int age;
};
class B : public A {
string name;
public:
void Print() {
cout << name << age;
}
};

Question 4

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
char *s = "ABCDEF";
cout << s+2;
return 0;
}

Question 5

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
#include <iostream>
using namespace std;
class First
{
public:
void Print(){ cout<<"from First";}
};
int main()
{
First t[2];
for (int i=0; i<2; i++)
t[i].Print();
}

Add Comments

Your email address will not be published. Required fields are marked *

insert code
Type the characters from the picture.