[May-2024] Check your preparation for C++ Institute CPA-21-02 On-Demand Exam
Practice Exam CPA-21-02 Realistic Dumps Verified Questions
NEW QUESTION # 108
What will be the output of the program?
#include <iostream>
#include <string>
using namespace std;
int fun(int);
int main()
{
float k=3;
k = fun(k);
cout<<k;
return 0;
}
int fun(int i)
{
i++;
return i;
}
- A. 0
- B. 5
- C. 1
- D. 2
Answer: D
NEW QUESTION # 109
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: 10
- B. It prints: 1
- C. It prints: 0
- D. It prints: ?1
Answer: B
NEW QUESTION # 110
What happens when you attempt to compile and run the following code?
- A. It prints: BACD
- B. It prints: BAD
- C. It prints: ABCD
- D. It prints: BAC
Answer: A
NEW QUESTION # 111
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. protected
- B. public
- C. None of these
- D. private
Answer: B
NEW QUESTION # 112
If a function, which is not a method, needs to save any value between its subsequent invocations, this can be done by: (Choose two.)
- A. setting a variable declared inside the function without the static modifier
- B. setting a variable declared inside the function with the static modifier
- C. setting a parameter of the function
- D. setting a variable declared outside the function
Answer: B,D
NEW QUESTION # 113
What will be the output of the program?
#include <iostream>
using namespace std;
int fun(int);
int main()
{
cout << fun(5);
return 0;
}
int fun(int i)
{
return i*i;
}
- A. 0
- B. 1
- C. 2
- D. 3
Answer: A
NEW QUESTION # 114
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int x=5;
static int y;
int i=0;
void static myFunction()
{
y=x++ + ++i;
}
int main (int argc, const char * argv[])
{
x++;
myFunction();
cout<<y<<" "<<x<< " " << i;
}
- A. It prints: 5 5 0
- B. Compilation fails
- C. It prints: 7 7 1
- D. It prints: 6 5 1
Answer: C
NEW QUESTION # 115
What happens when you attempt to compile and run the following code?
- A. It prints: 111
- B. It prints: 1
- C. It prints: 121
- D. lt prints: 2
Answer: C
NEW QUESTION # 116
Which line of code inserted instead of the comment will make the following code run properly without causing memory leaks?
- A. ~Base() ( delete this; }
- B. no additional code is needed
- C. ~Base() { delete ptr; delete ptr; }
- D. ~Base() { delete ptr; }
Answer: D
NEW QUESTION # 117
What happens when you attempt to compile and run the following code?
- A. It prints: 007
- B. It prints: 33
- C. It causes a compilation error
- D. lit prints: 9
Answer: C
NEW QUESTION # 118
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
#define DEF_A 0
int main(int argc, char *argv[]) {
cout << DEF_A;
return 0;
}
- A. It prints: 1
- B. It prints: ?1
- C. Compilation error
- D. It prints: 0
Answer: D
NEW QUESTION # 119
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) {}
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(2,5);
b.Print();
return 0;
}
- A. It prints: 10
- B. It prints: 5
- C. It prints: 1
- D. It prints: 2
Answer: A
NEW QUESTION # 120
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 address of ptr
- B. It prints: 20
- C. It prints: 0
- D. It prints: 2
Answer: B
NEW QUESTION # 121
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
A() { cout << "A no parameters";}
A(string s) { cout << "A string parameter";}
A(A &a) { cout << "A object A parameter";}
};
class B : public A {
public:
B() { cout << "B no parameters";}
B(string s) { cout << "B string parameter";}
B(int s) { cout << "B int parameter";}
};
int main () {
A a2("Test");
B b1(10);
B b2(b1);
return 0;
}
- A. It prints: A no parametersA no parameters
- B. It prints: A no parametersA no parametersB string parameter
- C. It prints: A no parametersB string parameter
- D. It prints: A string parameterA no parametersB int parameterA object A parameter
Answer: D
NEW QUESTION # 122
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
const char *s;
char str[] = "Hello ";
s = str;
while(*s) {
cout << *++s;
*s++;
}
return 0;
}
- A. The code will not compile.
- B. It will print:"el "
- C. It will print:"Hello "
- D. It will print garbage value
Answer: B
NEW QUESTION # 123
How many times will the program print "HELLO" ?
#include <iostream>
using namespace std;
int main()
{
cout<<"HELLO";
main();
return 0;
}
- A. 0
- B. 1
- C. Till stack overflows
- D. 2
Answer: C
NEW QUESTION # 124
......
Valid CPA-21-02 Dumps for Helping Passing C++ Institute Exam: https://pass4sure.updatedumps.com/c-plus-plus-institute/CPA-21-02-updated-exam-dumps.html