
CPA PDF Dumps Mar 31, 2022 Exam Questions – Valid CPA Dumps
Ultimate CPA Guide to Prepare Free Latest C++ Institute Practice Tests Dumps
NEW QUESTION 56
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int fun(int x);
int main() {
cout << fun(0);
return 0;
}
int fun(int x) {
if(x > 0)
return fun(x-1);
else
return 100;
}
- A. It prints: 100
- B. It prints: 0
- C. It prints: -1
- D. It prints: 10
Answer: A
NEW QUESTION 57
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
protected:
int y;
public:
int x,z;
A() : x(1), y(2), z(0) { z = x + y; }
A(int a, int b) : x(a), y(b) { z = x + y;}
void Print() { cout << z; }
};
class B : public A {
public:
int y;
B() : A() {}
B(int a, int b) : A(a,b) {}
void Print() { cout << z; }
};
int main () {
A b;
b.Print();
return 0;
}
- A. It prints: 0
- B. It prints: 2
- C. It prints: 1
- D. It prints: 3
Answer: D
NEW QUESTION 58
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class SampleClass
{
string *s;
public:
SampleClass() { s = new string("Text");}
SampleClass(string s) { this->s = new string(s);}
~SampleClass() { delete s;}
void Print(){ cout<<*s;}
};
int main()
{
SampleClass *obj;
obj = new SampleClass("Test");
obj->Print();
}
- A. It prints: Text
- B. It prints: Test
- C. It prints: TextTest
- D. Garbage value.
Answer: B
NEW QUESTION 59
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int i = 0;
do {
i++;
if (i==3)
break;
cout<<i;
}
while(i < 5);
return 0;
}
- A. It prints: 0
- B. It prints: 1
- C. It prints: 12
- D. No output
Answer: C
NEW QUESTION 60
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;
}
};
- A. public
- B. private
- C. None of these
- D. protected
Answer: D
NEW QUESTION 61
What happens when you attempt to compile and run the following code?
#include <cstdlib>
#include <iostream>
using namespace std;
float* sum(float a,float b);
float* sum(float a,float b)
{
float *f = new float;
*f = a+b;
return f;
}
int main()
{
float a,b,*f;
a = 1.5; b = 3.4;
f = sum(a,b);
cout<<*f;
return 0;
}
- A. It prints: 0
- B. It prints: 5
- C. It prints: 4.9
- D. It prints: 4
Answer: C
NEW QUESTION 62
What will the variable "y" be in class B?
class A {
int x;
protected:
int y;
public:
int age;
};
class B : private A {
string name;
public:
void Print() {
cout << name << age;
}
};
- A. public
- B. private
- C. protected
- D. None of these
Answer: B
NEW QUESTION 63
What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
union t
{
char c;
int i;
};
class First
{
union t u;
public:
First() {
u.c = 'A';
}
void Print(){
cout << u.c;
}
};
int main()
{
First *t = new First();
t?>Print();
}
- A. Compilation error
- B. It prints: A 65
- C. It prints: A
- D. Garbage value
Answer: C
NEW QUESTION 64
What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
class First
{
string name;
public:
First() {
name = "Alan";
}
void Print(){
cout << name;
}
};
int main()
{
First ob1,*ob2;
ob2 = new First();
ob1.Print(); ob2->Print(); }
- A. It prints: Al
- B. It prints: Alan
- C. It prints: AlanAlan
- D. Garbage value
Answer: C
NEW QUESTION 65
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:
int *tab;
B() { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;}
B(string s) : A(s) { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;}
~B() { delete tab; }
void Print() {
for (int i=0; i<size; i++) cout << tab[i];
cout << name;
}
};
int main () {
B b1("Alan");
B b2;
b1.tab[0]=0;
b1.Print(); b2.Print();
return 0;
}
- A. It prints: 0
- B. It prints: 011Alan111Bob
- C. It prints: Alan
- D. It prints: 111
Answer: B
NEW QUESTION 66
What happens when you attempt to compile and run the following code?
#include <iostream>
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: 0
- B. It prints: 21
- C. None of these
- D. It prints: 012
Answer: B
NEW QUESTION 67
What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
int main () {
string s1 = "Hello", s2 = "World";
s2 = s1 + s2;
cout << s2;
return 0;
}
- A. It prints: WorldHelloWorld
- B. It prints: WorldHello
- C. It prints: HelloWorld
- D. It prints: Hello
Answer: C
NEW QUESTION 68
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int f(int i);
int main()
{
int i=0;
i++;
for (i=0; i<=2; i++)
{
cout<<f(i);
}
return 0;
}
int f(int a)
{
return a+a;
}
- A. It prints: 0
- B. It prints: 024
- C. It prints: 012
- D. It prints: 202020
Answer: B
NEW QUESTION 69
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:
int *tab;
B() { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;}
B(string s) : A(s) { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;}
~B() { delete tab; }
void Print() {
for (int i=0; i<size; i++) cout << tab[i];
cout << name;
}
};
int main () {
B b1("Alan");
B b2;
b1.tab[0]=0;
b1.Print(); b2.Print();
return 0;
}
- A. It prints: 0
- B. It prints: 011Alan111Bob
- C. It prints: Alan
- D. It prints: 111
Answer: B
NEW QUESTION 70
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: 0
- B. It prints: 10
- C. It prints: 1
- D. It prints: 2
Answer: D
NEW QUESTION 71
What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1="Hello";
string s2="World";
s1+=s2;
cout << s1;
return( 0 );
}
- A. It prints: HelloWorld
- B. It prints: World
- C. It prints: Hello
- D. It prints: HelWorld
Answer: A
Explanation:
Section: Volume A
NEW QUESTION 72
......
Passing Key To Getting CPA Certified Exam Engine PDF: https://www.passsureexam.com/CPA-pass4sure-exam-dumps.html
Get Top-Rated C++ Institute CPA Exam Dumps Now: https://drive.google.com/open?id=15oKt0eef1MaLsJIQI145I1u9ts-PO2G9