Free CPA-21-02 Practice Test Questions and Answers (2026) | Cert Empire Practice Questions

Free preview: 20 questions.

Already purchased? Log in

C++ Institute CPA 21 02

View Mode
Q: 1
What happens when you attempt to compile and run the following code? #include 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:"; }
Options
Q: 2
What happens when you attempt to compile and run the following code? #include using namespace std; class A { public : void print() { cout << "A "; } }; class B { public : void print() { cout << "B "; } }; int main() { B sc[2]; B *bc = (B*)sc; for (int i=0; iprint(); return 0; }
Options
Q: 3
What happens when you attempt to compile and run the following code? C++ Institute CPA 21 02 question
Options
Q: 4
Which of the following is a user defined data type? 1: struct person { char name[20]; int age; }; 2: int l=2; 3: enum color {red,blue, green};
Options
Q: 5
What happens when you attempt to compile and run the following code? C++ Institute CPA 21 02 question
Options
Q: 6
What happens when you attempt to compile and run the following code? #include using namespace std; int main (int argc, const char * argv[]) { int tab[5]={1,2,3}; for (int i=0; i<5; i++) cout <<tab[i]; return 0; }
Options
Q: 7
What happens when you attempt to compile and run the following code? #include using namespace std; int main() { const char *s; char str[] = "Hello"; s = str; while(*s) { cout << *s++; } return 0; }
Options
Q: 8
What happens when you attempt to compile and run the following code? #include #include 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 ); }
Options
Q: 9
What happens when you attempt to compile and run the following code? C++ Institute CPA 21 02 question
Options
Q: 10
Which code, inserted at line 18, generates the output "AB" #include using namespace std; class A { public: void Print(){ cout<< "A";} void Print2(){ cout<< "a";} }; class B:public A { public: void Print(){ cout<< "B";} void Print2(){ cout<< "b";} }; int main() { B ob2; //insert code here ob2.Print(); }
Options
Q: 11
What happens when you attempt to compile and run the following code? C++ Institute CPA 21 02 question
Options
Q: 12
What will be the output of the program? #include #include 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; }
Options
Q: 13
What happens when you attempt to compile and run the following code? #include using namespace std; class A { public: virtual void Print(){ cout<<"A";} }; class B:public A { public: virtual void Print(){ cout<Print(); B ob2; obj = &ob2; obj?>Print(); }
Options
Q: 14
What happens when you attempt to compile and run the following code? #include #include 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"; } }
Options
Q: 15
Which code line inserted instead of the comment below will fix the program so that it produces the expected output and does not cause any memory leak? C++ Institute CPA 21 02 question
Options
Q: 16
What will happen if the memory cannot be allocated? C++ Institute CPA 21 02 question
Options
Q: 17
Which line of code inserted instead of the comment will make the following code run properly without causing memory leaks? C++ Institute CPA 21 02 question
Options
Q: 18
What happens if characters 'w', 'o', 'r', 'l' and 'd' are entered as input? #include #include using namespace std; int main() { string s1 = "Hello"; string s2; getline( cin, s2 ); cout << s1 + s2; return( 0 ); }
Options
Q: 19
Which of the following structures are correct? 1: struct s1{ int x; char c; }; 2: struct s2{ float f; struct s2 *s; }; 3: struct s3{ float f; in i; }
Options
Q: 20
What happens when you attempt to compile and run the following code? #include using namespace std; void print(char *c); int main (int argc, const char * argv[]) { print("Test"); return 0; } void print(char *c) { cout<<c; }
Options
Question 1 of 20

Premium Access Includes

  • Quiz Simulator
  • Exam Mode
  • Progress Tracking
  • Question Saving
  • Flash Cards
  • Drag & Drops
  • 3 Months Access
  • PDF Downloads
Get Premium Access
Scroll to Top

FLASH OFFER

Days
Hours
Minutes
Seconds

avail 10% DISCOUNT on YOUR PURCHASE