2024 ExamPrepAway C++ Institute CPA-21-02 Dumps and Exam Test Engine
C++ Institute CPA-21-02 DUMPS WITH REAL EXAM QUESTIONS
NEW QUESTION # 137
If there is one, point out an error in the program
#include <iostream>
using namespace std;
int main()
{
int i=1;
for(;;)
{
cout<<i++;
if(i>5)
break;
}
return 0;
}
- A. Error in "for" loop
- B. No error
- C. Error in break statement
- D. Error in "if" statement
Answer: B
NEW QUESTION # 138
What happens when you attempt to compile and run the following code?
- A. It prints: 0
- B. It prints: 1
- C. It prints: -1
- D. It causes a compilation error
Answer: D
NEW QUESTION # 139
How could you pass arguments to functions?
- A. by void
- B. by reference
- C. by pointer
- D. by value
Answer: B,C,D
NEW QUESTION # 140
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: 000
- B. It prints: 23
- C. It prints: 12
- D. It prints: 123
Answer: B
NEW QUESTION # 141
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(2), y(2), z(1) { 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: 4
- B. It prints: 0
- C. It prints: 2
- D. It prints: 3
Answer: A
NEW QUESTION # 142
What is the output of the program?
#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
void setAge(int a=10) {age = a;}
void Print() { cout << age;}
};
int Base::age=0;
int main () {
Base a,*b;
b = new Base();
a.setAge();
b?>setAge(20);
a.Print();
b?>Print();
return 0;
}
- A. It prints: 10
- B. It prints: 1020
- C. It prints: 2020
- D. It prints: 20
Answer: C
NEW QUESTION # 143
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. protected
- C. private
- D. None of these
Answer: B
NEW QUESTION # 144
What is the expected result of the following program?
- A. It prints: ACDB
- B. It prints: ACBD
- C. It prints: ABCD
- D. It prints: CABD
Answer: B
NEW QUESTION # 145
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: A
NEW QUESTION # 146
What happens when you attempt to compile and run the following code?
- A. It prints: 0
- B. It prints: 1
- C. It prints: -1
- D. It causes a compilation error
Answer: B
NEW QUESTION # 147
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: 0
- B. It prints: 01245
- C. It prints: 012345
- D. It prints: 05
Answer: B
NEW QUESTION # 148
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;
A() { x=1; y=2; z=3; }
};
class B : public A {
string z;
public:
void set() {
y = 4;
z = "John";
}
void Print() {
cout << y << z;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
- A. It prints: 2John
- B. It prints: 43
- C. It prints: 4John
- D. It prints: 23
Answer: C
NEW QUESTION # 149
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
NEW QUESTION # 150
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class complex{
double re;
double im;
public:
complex() : re(1),im(0.4) {}
bool operator==(complex &t);
};
bool complex::operator == (complex &t){
if((this?>re == t.re) && (this?>im == t.im))
return true;
else
return false;
}
int main(){
complex c1,c2;
if (c1==c2)
cout << "OK";
else {
cout << "ERROR";
}
}
- A. It prints: ERROR
- B. It prints: OK
- C. Compilation error
- D. Runtime error.
Answer: B
NEW QUESTION # 151
What is the output of the program?
#include <iostream>
using namespace std;
int main()
{
int tab[4]={10,20,30,40};
tab[1]=10;
int *p;
p=&tab[0];
cout<<*p;
return 0;
}
- A. It prints: 11
- B. It prints: 30
- C. It prints: 20
- D. It prints: 10
Answer: D
NEW QUESTION # 152
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class Base
{
string s;
public:
Base() { s="Sample text";}
Base(string s) { this?>s=s; }
void Print() { cout << s; }
};
int main()
{
Base *o = new Base();
o?>Print();
}
- A. It prints: Sample text
- B. It prints: text
- C. It prints: Sample
- D. None of these
Answer: A
NEW QUESTION # 153
What is the output of the program?
#include <iostream>
using namespace std;
class BaseC
{
int i;
public:
BaseC() { i=?1;}
BaseC(int i) { i=i; }
void seti(int a) { i = a; };
void Print() { cout << i; }
};
int main()
{
BaseC *o = new BaseC();
o?>seti(10);
o?>Print();
}
- A. It prints: ?1
- B. It prints: 0
- C. Compilation error
- D. It prints: 10
Answer: D
NEW QUESTION # 154
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class First
{
public:
void Print(){ cout<<"from First";}
};
class Second
{
public:
void Print(){ cout<< "from Second";}
};
int main()
{
Second t[2];
for (int i=0; i<2; i++)
t[i].Print();
}
- A. It prints: from Secondfrom Second
- B. It prints: from Firstfrom First
- C. It prints: from Second
- D. It prints: from First
Answer: A
NEW QUESTION # 155
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class A
{
public:
virtual void Print(){ cout<<"A";}
};
class B:public A
{
public:
void Print(){ cout<< "B";}
};
int main()
{
A *obj;
A ob1;
obj = &ob1;
obj?>Print();
B ob2;
obj = &ob2;
obj?>Print();
}
- A. It prints: BB
- B. It prints: BA
- C. It prints: AB
- D. It prints: AA
Answer: C
NEW QUESTION # 156
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class complex{
double re, im;
public:
complex() : re(1),im(0.3) {}
complex(double n) { re=n,im=n;};
complex(int m,int n) { re=m,im=n;}
complex operator+(complex &t);
void Print() { cout << re << " " << im; }
};
complex complex::operator+ (complex &t){
complex temp;
temp.re = this?>re + t.re;
temp.im = this?>im + t.im;
return temp;
}
int main(){
complex c1(1),c2(2),c3;
c3 = c1 + c2;
c3.Print();
}
- A. It prints: 2 1.5
- B. It prints: 0 0
- C. It prints: 1 1.5
- D. It prints: 3 3
Answer: D
NEW QUESTION # 157
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()
{
float *pf;
float f=0.9;
pf=&f;
cout << op(1, *pf);
return 0;
}
int op(int x, int y)
{
return x*y;
}
- A. It prints: ?1
- B. It prints: 1
- C. It prints: 0
- D. It prints: 0.5
Answer: C
NEW QUESTION # 158
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. It prints: 0
- D. Compilation error
Answer: C
NEW QUESTION # 159
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int *a= new int;
*a=100;
cout << *a;
delete a;
}
- A. It prints: 10
- B. It prints: 0
- C. It prints: 1
- D. It prints: 100
Answer: D
NEW QUESTION # 160
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 B:public A {
public:
virtual void Print(){ cout<< "B"; }
};
class C:public B {
public:
void Print(){ cout<< "C"; }
};
int main()
{
A ob1;
B ob2;
C ob3;
A *obj;
obj = &ob1;
obj?>Print();
obj = &ob2;
obj?>Print();
obj = &ob3;
obj?>Print();
}
- A. It prints: ABC
- B. It prints: ABB
- C. It prints: AAA
- D. It prints: BBB
Answer: C
NEW QUESTION # 161
Which of the following operations is INCORRECT?
- A. int i=15;
- B. float f=12,2;
- C. long int k=123
- D. double d=12;
Answer: B
NEW QUESTION # 162
......
2024 New ExamPrepAway CPA-21-02 PDF Recently Updated Questions: https://www.examprepaway.com/c-plus-plus-institute/braindumps.CPA-21-02.ete.file.html
CPA-21-02 Exam with Guarantee Updated 256 Questions: https://drive.google.com/open?id=1KA89z-aaIalsvlVUpndOUvSkPI9j5S92