CPA-21-02 Exam Questions Dumps, Selling C++ Institute Products [Q130-Q145]

Share

CPA-21-02 Exam Questions Dumps, Selling C++ Institute Products

CPA-21-02 Cert Guide PDF 100% Cover Real Exam Questions

NEW QUESTION # 130
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
const int size = 3;
class A {
public:
string name;
A() { name = "Bob";}
A(string s) { name = s;}
A(A &a) { name = a.name;}
};
class B : public A {
public:
B() { }
B(string s) : A(s) { }
void Print() {
cout << name;
}
};
int main () {
B b1("Alan");
b1.Print();
return 0;
}

  • A. It prints: Alan
  • B. It prints: 0
  • C. It prints: 111Alan
  • D. It prints: Bob

Answer: A


NEW QUESTION # 131
What happens when you attempt to compile and run the following code?

  • A. It prints: 0
  • B. It prints: 4
  • C. It prints: 6
  • D. It prints: 3

Answer: C


NEW QUESTION # 132
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class First
{
public:
First() { cout << "Constructor";}
~First() { cout << "Destructor";}
void Print(){ cout<<"from First";}
};
int main()
{
First FirstObject;
FirstObject.Print();
}

  • A. It prints: Constructorfrom FirstDestructorDestructor
  • B. It prints: Constructorfrom First
  • C. It prints: Constructorfrom FirstDestructor
  • D. Compilation error at line 16

Answer: C


NEW QUESTION # 133
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int fun(int x) {
return 2*x;
}
int main(){
int i;
i = fun(1) || fun(2);
cout << i;
return 0;
}

  • A. Compilation error
  • B. It prints: 0
  • C. It prints: -1
  • D. It prints: 1

Answer: D


NEW QUESTION # 134
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;
}

  • A. Compilation error
  • B. It prints: 0
  • C. It prints: 1
  • D. It prints address of x

Answer: B


NEW QUESTION # 135
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 :
void print() {
cout << "B ";
}
};
int main() {
B sc[2];
B *bc = (B*)sc;
for (int i=0; i<2;i++)
(bc++)->print();
return 0;
}

  • A. It prints: A B
  • B. It prints: B A
  • C. It prints: A A
  • D. It prints: B B

Answer: D


NEW QUESTION # 136
What happens when you attempt to compile and run the following code?

  • A. It pints: AABD
  • B. It causes a compilation error
  • C. It prints: AABDD
  • D. It prints: AAABDD

Answer: B


NEW QUESTION # 137
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int getValue();
int main()
{
const int x = getValue();
cout<<x;
return 0;
}
int getValue()
{
return 5;
}

  • A. It will print 5
  • B. It will print 0
  • C. The code will not compile.
  • D. It will print garbage value

Answer: A


NEW QUESTION # 138
What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
int main()
{
char str[] = "Hello\0\World\0";
cout << str;
return 0;
}

  • A. It prints: Hello
  • B. It prints: HW
  • C. It prints: World
  • D. It prints: World\0World

Answer: A


NEW QUESTION # 139
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();
}

  • A. It prints: Constructorfrom First
  • B. None of these
  • C. It prints: Constructor
  • D. It prints: from First

Answer: A


NEW QUESTION # 140
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
#define DEF_A 0
#define DEF_B DEF_A+1
#define DEF_C DEF_B+1
int main(int argc, char *argv[]) {
cout << DEF_C;
return 0;
}

  • A. It prints: 2
  • B. It prints: 0
  • C. It prints: 1
  • D. It prints: 10

Answer: A


NEW QUESTION # 141
Which code, inserted at line 14, generates the output "3.14 10"?
#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 () {
//insert code here
cout << x << " " << y;
return 0;
}

  • A. using namespace myNamespace1;
  • B. using myNamespace1::y; using myNamespace2::x;
  • C. using namespace myNamespace1; using namespace myNamespace2;
  • D. using myNamespace2::y; using myNamespace1::x;

Answer: B


NEW QUESTION # 142
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main() {
int i, j;
for(i = 0; i < 2; i++) {
for(j = i; j < i + 1; j++)
if(j == i)
continue;
else
break;
}
cout << j;
return 0;
}

  • A. It prints: 2
  • B. It prints: 0
  • C. It prints: 3
  • D. It prints: 1

Answer: A


NEW QUESTION # 143
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class complex{
double re, im;
public:
complex() : re(1),im(0.4) {}
complex operator?(complex &t);
void Print() { cout << re << " " << im; }
};
complex complex::operator? (complex &t){
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: 2 0.8
  • B. It prints: 1 0.4
  • C. It prints: 0 0
  • D. It prints: 1 0.8

Answer: C


NEW QUESTION # 144
What is the output of the program if character 4 is supplied as input?
#include <iostream>
using namespace std;
int main () {
int c;
cin >> c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
case 3:
throw 'a';
default:
cout<<"No exception";
}
}
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: No exception
  • B. It prints: An exception occurred
  • C. It prints: float exception. Exception Nr.
  • D. It prints: int exception. Exception Nr.

Answer: A


NEW QUESTION # 145
......

Pass CPA-21-02 Exam - Real Questions and Answers: https://examcollection.dumpsvalid.com/CPA-21-02-brain-dumps.html