Master the CPA C++ Certified Associate Programmer content and be ready for exam day success quickly with this Pass4sure CPA free exam questions. We guarantee it!We make it a reality and give you real CPA questions in our C++ Institute CPA braindumps.Latest 100% VALID C++ Institute CPA Exam Questions Dumps at below page. You can use our C++ Institute CPA braindumps and pass your exam.
Q97. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
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.
Answer: D
Q98. - (Topic 1)
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: Hello
C. It prints: World
D. It prints: HelWorld
Answer: A
Q99. - (Topic 1)
What will the variable "age" be in class B?
class A {
int x;
protected:
int y;
public:
int age;
A () { age=5; };
};
class B : public A {
string name;
public:
B () { name="Bob"; };
void Print() {
cout << name << age;
}
};
A. public
B. private
C. protected
D. None of these
Answer: A
Q100. - (Topic 2)
What will happen when you attempt to compile and run the following code? #include <iostream>
using namespace std;
#define A 1
int main()
{
#if A
cout<<"Hello";
#endif
cout<<"world";
return 0;
}
A. It will print: Helloworld
B. It will print: Hello
C. It will print: world
D. It will print: 0
Answer: A
Q101. - (Topic 2)
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 C:public A {
public:
virtual void Print()=0;
};
int main()
{
C obj3;
obj3?>Print();
}
A. It prints: BB
B. It prints: A
C. It prints: AB
D. Compilation error
Answer: D
Q102. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main() { int x=20; int *ptr; ptr = &x; cout<<*ptr; return 0; }
A. It prints: 20
B. It prints: 0
C. It prints address of ptr
D. It prints: 2
Answer: A
Q103. - (Topic 1)
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. It prints: 0
B. It prints address of x
C. It prints: 1
D. Compilation error
Answer: A
Q104. - (Topic 1)
Which code, inserted at line 8, generates the output "0102021"?
#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
//insert code here void Print() { cout << age;} };
int Base::age=0;
int main () { Base a,*b; b = new Base(); a.Print(); a.setAge(10); a.Print(); b?>setAge(); a.Print(); b?>Print(); return 0; }
A. void setAge(int a) {age = a;}
B. void setAge() {age = 20;}
C. void setAge() {age = 10;}
D. void setAge(int a=20) {age = a;}
Answer: D
Q105. - (Topic 2)
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. It prints: Constructor
C. It prints: from First
D. None of these
Answer: A
Q106. - (Topic 2)
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int mul (int a, int b=2)
{
int r;
r=a*b;
return (r);
}
int main ()
{
cout << mul(1) << mul(2,4);
return 0;
}
A. It prints: 2
B. It prints: 28
C. It prints: 8
D. It prints: 6
Answer: B
Q107. - (Topic 2)
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class A
{
public:
virtual void Print()=0;
};
class B:public A
{
public:
virtual void Print(){ cout<< "B";}
};
int main()
{
B ob2;
A *obj;
obj = &ob2;
obj?>Print();
}
A. It prints: B
B. It prints: A
C. It prints: AB
D. It prints: BA
Answer: A
Q108. - (Topic 2)
What is not inherited from the base class?
A. constructor
B. destructor
C. operator=()
D. operator+()
Answer: A,B,C
Q109. - (Topic 2)
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int op(int x, int y);
int main()
{
int i=2, j=2, k;
float f=0.3;
k = op(i, j);
cout<< k << "," << op(1, f);
return 0;
}
int op(int x, int y)
{
return x+y;
}
A. It prints: 4,1
B. It prints: 4,0.7
C. It prints: 4,0
D. It prints: 0,4
Answer: A
209. - (Topic 2)
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1[]= {"How" , "to" };
s1[0].swap(s1[1]);
for (int i=0; i<2; i++) {
cout << s1[i];
}
return( 0 );
}
A. It prints: Hoto
B. It prints: toHow
C. It prints: Ht
D. It prints: to
Answer: B
Q110. - (Topic 2)
What happens when you attempt to compile and run the following code? #include <iostream>
using namespace std;
int main()
{
int *t;
t = new int[2];
for (int i=0; i<2; i++) {
t[i] = i;
}
cout << t[1];
}
A. It prints: 0
B. It prints: 1
C. It prints: 10
D. It prints: ?1
Answer: B
Q111. - (Topic 1)
Which of the structures is incorrect?
1:
struct s1{ int x; long int li;
};
2:
struct s2{ float f; struct s2 *s;
};
3:
struct s3{ float f; struct s3 s; };
A. 1
B. 2
C. 3
D. 2, 3
Answer: C
Q112. - (Topic 2)
How many times will the program print "HELLO" ? #include <iostream>
using namespace std;
int main()
{
cout<<"HELLO";
main();
return 0;
}
A. 65536
B. 32769
C. 1
D. Till stack overflows
Answer: D