[Jul 12, 2024] Download Free C++ Institute CPA-21-02 Real Exam Questions [Q117-Q133]

Share

[Jul 12, 2024] Download Free C++ Institute CPA-21-02 Real Exam Questions

Pass Your Exam With 100% Verified CPA-21-02 Exam Questions

NEW QUESTION # 117
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class Base {
int age;
public:
class C {
int b;
void PrintC() { cout << b; }
};
Base () {age=5;};
void setAge(int a=20) {age = a;}
void Print() { cout << age;}
};
int main () {
Base a;
a.setAge(10);
a.Print();
return 0;
}

  • A. It prints: 20
  • B. It prints: 10
  • C. It prints: 1020
  • D. It prints: 105

Answer: B


NEW QUESTION # 118
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double x) { re=x,im=x;};
complex(double x,double y) { re=x,im=y;}
void print() { cout << re << " " << im;}
};
int main(){
complex c1;
c1 = 3.0;
c1.print();
return 0;
}

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

Answer: D


NEW QUESTION # 119
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(0);
cout << i;
return 0;
}

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

Answer: A


NEW QUESTION # 120
Which of the following statements are correct about an array?
int tab[10];

  • A. It is necessary to initialize the array at the time of declaration.
  • B. The expression tab[1] designates the very first element in the array.
  • C. The expression tab[9] designates the last element in the array.
  • D. The array can store 10 elements.

Answer: C,D


NEW QUESTION # 121
What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1="World";
string s2;
s2="Hello" + s1;
cout << s2;
return( 0 );
}

  • A. It prints: HelloWorld
  • B. It prints: World
  • C. It prints: Hello
  • D. Compilation error

Answer: A


NEW QUESTION # 122
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class First
{
public:
virtual void Print(){ cout<<"from First";}
};
class Second:public First
{
public:
void Print(){ cout<< "from Second";}
};
void fun(First *obj);
int main()
{
First FirstObject;
fun(&FirstObject);
Second SecondObject;
fun(&SecondObject);
}
void fun(First *obj)
{
obj?>Print();
}

  • A. It prints: from First
  • B. It prints: from Secondfrom Second
  • C. It prints: from Firstfrom First
  • D. It prints: from Firstfrom Second

Answer: D


NEW QUESTION # 123
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int x=2, *y;
y = &x;
cout << *y + x;
return 0;
}

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

Answer: D


NEW QUESTION # 124
Which definitions are correct?

  • A. int char;
  • B. char c;
  • C. int double;
  • D. int age;

Answer: B,D


NEW QUESTION # 125
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 with the static modifier
  • B. setting a variable declared inside the function without the static modifier
  • C. setting a parameter of the function
  • D. setting a variable declared outside the function

Answer: A,D


NEW QUESTION # 126
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
void fun(int i);
int main()
{
int i=0;
i++;
for (i=0; i<=5; i++)
{
fun(i);
}
return 0;
}
void fun(int i)
{
if (i==3)
return;
cout << i;
}

  • A. It prints: 012345
  • B. It prints: 05
  • C. It prints: 0
  • D. It prints: 01245

Answer: D


NEW QUESTION # 127
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. It prints: -1
  • B. It prints: 0
  • C. Compilation error
  • D. It prints: 1

Answer: D


NEW QUESTION # 128
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: World
  • B. It prints: World\0World
  • C. It prints: Hello
  • D. It prints: HW

Answer: C


NEW QUESTION # 129
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int compare(int, int);
int main()
{
int x = compare(10, 20);
cout << x;
return 0;
}
int compare(int i, int j)
{
return i<j;
}

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

Answer: D


NEW QUESTION # 130
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int i=2;
switch(i)
{
case 1:
cout<<"Hello";
break;
case 2:
cout<<"world";
break;
case 3:
printf("End");
break;
}
return 0;
}

  • A. It prints: world
  • B. It prints: E
  • C. It prints: End
  • D. It prints: Hello

Answer: A


NEW QUESTION # 131
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
struct Person {
string name;
int age;
};
class First
{
Person *person;
public:
First() {person = new Person;
person?>name = "John";
person?>age = 30;
}
void Print(){
cout<<person?>name << " "<< person?>age;
}
};
int main()
{
First t[2];
for (int i=0; i<2; i++)
t[i].Print();
}

  • A. It prints: John
  • B. It prints: 30
  • C. It prints: John 31
  • D. It prints: John 30John 30

Answer: D


NEW QUESTION # 132
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: 2
  • C. It prints: 1
  • D. It prints: 5

Answer: A


NEW QUESTION # 133
......

CPA-21-02 Dumps 100 Pass Guarantee With Latest Demo: https://www.pass4cram.com/CPA-21-02_free-download.html

CPA-21-02 Dumps PDF - CPA-21-02 Real Exam Questions Answers: https://drive.google.com/open?id=1ialg-4ZBKI7Lpr_w8TEtmEa-bJnivbLl