C++ Institute certification practice

CPA-21-02 Practice Questions

Try 10 free CPA-21-02 exam-style questions for CPA - C++ Certified Associate Programmer. Check each answer and review the explanation and source references.

Exam code
CPA-21-02
Provider
C++ Institute
Free questions
10
Full set
257 questions
Last update check
What happens when you attempt to compile and run the following code? #include using namespace std; int main(){ int i, j; for(i = 0, j = 1; j < 2, i < 4; i++, j++); cout << i << " " << j; return 0; }
Answer options
What happens when you attempt to compile and run the following code? #include #include using namespace std; int f(int i, int b); int main() { int i=0; i++; for (i=0; i<=2; i++) { cout<<f(0,i); } return 0; } int f(int a, int b) { return a+b; }
Answer options
Which of the following statements are correct about an array? int tab[10];
Answer options
What happens when you attempt to compile and run the following code? #include #include using namespace std; class myClass : public exception { virtual const char* what() const throw() { return "My exception."; } } obj; int main () { try { throw obj; } catch (exception& e) { cout << e.what() << endl; } return 0; }
Answer options
What is the output of the program if characters 'h', 'e', 'l', 'l' , 'o' and enter are supplied as input? #include #include using namespace std; void f(); int main() { f(); return 0; } void f() { char c; c = cin.get(); cout << c; if(c != '\n') f(); }
Answer options
What happens when you attempt to compile and run the following code? #include 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; double i=2; c1 = i; c1.print(); return 0; }
Answer options
What happens when you attempt to compile and run the following code? #include using namespace std; int main(){ int i = 1; for(i=10; i>-1; i/=2) { if(!i) break; } cout << i; return 0; }
Answer options
What is the output of the program? #include #include using namespace std; int main() { char str[] = "Hello\0\World\0"; cout << str; return 0; }
Answer options
What happens when you attempt to compile and run the following code? #include 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; }
Answer options
What happens when you attempt to compile and run the following code? #include #include using namespace std; class A { public: string s; A(string s) { this?>s = s; } }; class B { public: string s; B (A a) { this?>s = a.s; } void print() { cout<<s; } }; int main() { A a("Hello world"); B b=a; b.print(); }
Answer options
Question 1 of 10

Source context

How this practice set is maintained

Maintained by the CertMage content team, this page loads questions from the exam dataset connected to its preparation resource. When an answer includes a supporting reference, it is shown with that answer so you can review the underlying vendor documentation.

Certification objectives, interfaces, and vendor services can change. Verify important details against the provider's current exam guide and documentation before your exam.

Scroll to Top