We provide real CPA exam questions and answers braindumps in two formats. Download PDF & Practice Tests. Pass C++ Institute CPA Exam quickly & easily. The CPA PDF type is available for reading and printing. You can print more and practice many times. With the help of our C++ Institute CPA dumps pdf and vce product and material, you can easily pass the CPA exam.
Q65. - (Topic 2)
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
string fun(string, string);
int main()
{
string s="Hello";
cout << fun(s, " World");
return 0;
}
string fun(string s1, string s2)
{
return s1+s2;
}
A. It will print: Hello World
B. It will print: Hello
C. It will print: World
D. It will print: HW
Answer: A
Q66. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
A() { cout << "A0 ";}
A(string s) { cout << "A1";}
};
class B : public A {
public:
B() { cout << "B0 ";}
B(string s) { cout << "B1 ";}
};
class C : private B {
public:
C() { cout << "C0 ";}
C(string s) { cout << "C1 ";}
};
int main () {
B b1;
C c1;
return 0;
}
A. It prints: A0 B0 A0 B1 A0 C0 A0 C1
B. It prints: B0 B1 C0 C1
C. It prints: A0 B0 A0 B0 C0
D. It prints: B0 B1
Answer: C
Q67. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int s(int n);
int main()
{
int a;
a = 3;
cout << s(a);
return 0;
}
int s(int n)
{
if(n == 0) return 1;
return s(n?1)*n;
}
A. It prints: 4
B. It prints: 6
C. It prints: 3
D. It prints: 0
Answer: B
Q68. - (Topic 1)
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();
}
A. It prints: from First
B. It prints: from Firstfrom First
C. Compilation error
D. Runtime error.
Answer: B
106. - (Topic 1)
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;
}
A. It prints: CDEF
B. It prints: ABCDEF
C. It prints: BCDEF
D. None of these
Answer: A
Q69. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class BaseC
{
int *ptr;
public:
BaseC() { ptr = new int(10);}
BaseC(int i) { ptr = new int(i); }
~BaseC() { delete ptr; }
void Print() { cout << *ptr; }
};
int main()
{
BaseC *o = new BaseC(5);
o?>Print();
}
A. It prints: 5
B. It prints: 10
C. It prints: 1
D. It prints: 0
Answer: A
Q70. - (Topic 2)
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: Alan
B. It prints: 111
C. It prints: 011Alan111Bob
D. It prints: 0
Answer: C
Q71. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
const int x=20;
const int *ptr;
ptr = &x;
*ptr = 10;
cout<<*ptr;
return 0;
}
A. It prints: 20
B. It prints: 10
C. Compilation error at line 8
D. It prints address of ptr
Answer: C
Q72. - (Topic 1)
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: 21
B. It prints: 012
C. It prints: 0
D. None of these
Answer: A
Q73. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
int x;
protected:
int y;
public:
int z;
};
class B : public A {
string name;
public:
void set() {
y = 2;
z = 3;
}
void Print() { cout << y << z; }
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
A. It prints: 123
B. It prints: 000
C. It prints: 23
D. It prints: 12
Answer: C
Q74. - (Topic 2)
What is the output of the program? #include <iostream>
using namespace std;
#define PRINT(i) cout<<i;
int main()
{
int y=2, z=3;
PRINT(y);
PRINT(z);
return 0;
}
A. It prints: 123
B. It prints: 23
C. It prints: 3
D. It prints: 2
Answer: B
Q75. - (Topic 2)
What is the output of the program given below? #include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
float f=?10.501;
cout<<(int)f;
}
A. 0
B. 11
C. ?10
D. ?11
Answer: C
Q76. - (Topic 2)
What happens when you attempt to compile and run the following code? #include <iostream>
using namespace std;
int min(int a, int b);
int main()
{
int min(int,int);
int b;
b = min(10,20);
cout << b;
return 0;
}
int min(int a, int b)
{
return(b);
}
A. It prints: 20
B. It prints: 10
C. It prints: 1020
D. It prints: 2010
Answer: A
Q77. - (Topic 1)
Which of the following is a logical operator?
A. & B. &&
C. ||
D. !
Answer: B,C,D
Q78. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
int x,y;
union t
{
char tab[2];
int i;
};
union t u;
u.tab[0] = 1;
u.tab[1] = 2;
u.i = 0; x = u.tab[0]; y = u.tab[1];
cout << x << "," << y << "," << u.i;
return 0;
}
A. compilation fails
B. It prints: 0,0,0
C. It prints: 1,2,0
D. None of these
Answer: B
Q79. - (Topic 2)
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: 12
B. It prints: 1
C. It prints: 0
D. No output
Answer: A
Q80. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
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
Answer: D