Real C++ Institute CPA-21-02 Exam Questions Study Guide
Updated and Accurate CPA-21-02 Questions for passing the exam Quickly
NEW QUESTION # 116
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
float x=3.5,y=1.6;
int i,j=2;
i = x + j + y;
cout << i;
return 0;
}
- A. It prints: 7
- B. Compilation error
- C. It prints: 7,1
- D. It prints: 6
Answer: A
NEW QUESTION # 117
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 First
- B. It prints: from Firstfrom First
- C. It prints: from Secondfrom Second
- D. It prints: from Second
Answer: C
NEW QUESTION # 118
What is the output of the program if character 2 is supplied as input?
#include <iostream>
using namespace std;
int main () {
int c;
cin >> c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (float e)
{ cout << "float exception. Exception Nr. " << e; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}
- A. It prints: An exception occurred
- B. It prints: float exception. Exception Nr.
- C. It prints: float exception. Exception Nr. 5.2
- D. It prints: int exception. Exception Nr. 20
Answer: C
NEW QUESTION # 119
What happens when you attempt to compile and run the following code?
- A. It prints: 1
- B. It prints: -1
- C. It prints: 0
- D. It causes a compilation error
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 argc, const char * argv[])
{
int a = 30, b = 1, c = 5, i=10;
i = b < a < c;
cout << i;
return 0;
}
- A. It prints: 1
- B. It prints: 10
- C. It prints: 0
- D. compilation fails
Answer: A
NEW QUESTION # 121
Which code, inserted at line 10, generate the output "50"?
#include <iostream>
using namespace std;
class Base {
int age;
public:
Base () {
age=5;
};
//insert code here
void Print() { cout << age;}
};
void setAge(Base &ob) {ob.age = 0;}
int main () {
Base a;
a.Print();
setAge(a);
a.Print();
return 0;
}
- A. friend void setAge(Base *ob);
- B. None of these
- C. friend void setAge(Base &ob);
- D. friend void setAge(Base ob);
Answer: C
NEW QUESTION # 122
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int op(int x, int y)
{
return x?y;
}
int op(int x, float y)
{
return x+y;
}
int main()
{
int i=1, j=2, k, l;
float f=0.23;
k = op(i, j);
l = op(j, f);
cout<< k << "," << l;
return 0;
}
- A. Compilation fails
- B. It prints: ?1,2
- C. It prints: ?1,?1
- D. It prints: ?1,3
Answer: B
NEW QUESTION # 123
Which code, inserted at line 14, generates the output "3.14 10"?
#include <iostream>
using namespace std;
namespace myNamespace1
{
int x = 5;
int y = 10;
}
namespace myNamespace2
{
float x = 3.14;
float y = 1.5;
}
int main () {
//insert code here
cout << x << " " << y;
return 0;
}
- A. using namespace myNamespace1; using namespace myNamespace2;
- B. using myNamespace1::y; using myNamespace2::x;
- C. using myNamespace2::y; using myNamespace1::x;
- D. using namespace myNamespace1;
Answer: B
NEW QUESTION # 124
What happens when you attempt to compile and run the following code?
#include <cstdlib>
#include <iostream>
using namespace std;
float* sum(float a,float b);
float* sum(float a,float b)
{
float *f = new float;
*f = a+b;
return f;
}
int main()
{
float a,b,*f;
a = 1.5; b = 3.4;
f = sum(a,b);
cout<<*f;
return 0;
}
- A. It prints: 0
- B. It prints: 5
- C. It prints: 4
- D. It prints: 4.9
Answer: D
NEW QUESTION # 125
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void fun(int*);
int main()
{
int *x;
int i=2;
x=&i;
fun(x);
cout<<i;
return 0;
}
void fun(int *i)
{
*i = *i * *i;
}
- A. It prints: 0
- B. It prints: 4
- C. It prints: 1
- D. It prints: 2
Answer: B
NEW QUESTION # 126
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: -1
- B. Compilation error
- C. It prints: 1
- D. It prints: 0
Answer: D
NEW QUESTION # 127
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1[]= {"H" , "t" };
string s;
for (int i=0; i<2; i++) {
s = s1[i];
s.insert(1,"o");
cout << s;
}
return( 0 );
}
- A. It prints: Hoto
- B. It prints: Ho
- C. It prints: Ht
- D. It prints: to
Answer: A
NEW QUESTION # 128
What happens when you attempt to compile and run the following code?
- A. It prints: -31
- B. It prints: 33
- C. It prints: -13
- D. It prints: -1-1
Answer: C
NEW QUESTION # 129
What is the output of the program if characters 'h', 'e', 'l', 'l' , 'o' and enter are supplied as input?
#include <iostream>
#include <string>
using namespace std;
void f();
int main()
{
f();
return 0;
}
void f()
{
char c;
c = cin.get();
cout << c;
if(c != '\n')
f();
}
- A. It prints: h
- B. It prints: hello
- C. It prints: o
- D. It prints: olleh
Answer: B
NEW QUESTION # 130
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: C
NEW QUESTION # 131
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. It prints: 1,2,0
- B. compilation fails
- C. None of these
- D. It prints: 0,0,0
Answer: D
NEW QUESTION # 132
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: Hello
- B. It prints: World
- C. Compilation error
- D. It prints: HelloWorld
Answer: D
NEW QUESTION # 133
What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
class First
{
string name;
public:
First() {
name = "Alan";
}
void setName(string n) {this?>name = n;}
void setName() {this?>name = "John";}
void Print(){
cout << name;
}
};
int main()
{
First ob1,*ob2;
ob2 = new First();
First *t;
t = &ob1;
t?>setName();
t?>Print();
t = ob2;
t?>setName("Steve");
ob2?>Print();
}
- A. It prints: JohnAlan
- B. It prints: AlanAlan
- C. It prints: JohnSteve
- D. It prints: AlanSteve
Answer: C
NEW QUESTION # 134
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: 6 5 1
- B. Compilation fails
- C. It prints: 5 5 0
- D. It prints: 7 7 1
Answer: D
NEW QUESTION # 135
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class Test {
float i,j;
};
class Add {
public:
int x,y;
Add (int a=3, int b=3) { x=a; y=b; }
int result() { return x+y;}
};
int main () {
Test test;
Add * padd;
padd = &test;
cout << padd?>result();
return 0;
}
- A. It prints: 9
- B. It prints: 33
- C. It prints: 6
- D. Compilation error
Answer: D
NEW QUESTION # 136
What happens when you attempt to compile and run the following code?
- A. It prints: 5.2110.0
- B. It prints: 5210
- C. It prints: 52.10
- D. It prints: 5.210.0
Answer: C
NEW QUESTION # 137
......
Prepare Important Exam with CPA-21-02 Exam Dumps: https://vcetorrent.passreview.com/CPA-21-02-exam-questions.html