C++ CERTIFIED

ASSOCIATE
PROGRAMMER - CPA
Sample Exam Questions

C++ Institute | 2016 | All Rights reserved.
www.cppinstitute.org

Question 1

What is the output of the following program?

#include <iostream>
using namespace std;
int main(void) {
int i = 1, j = 2;
if(i > j && j > i)
i++;
if(i > j || j > i)
j++;
if(i | j)
i++;
if(i & j)
j++;
cout << i * j << endl;
return 0;
}

A. 2
B. 3
C. 6
D. 8

C++ Institute. 2016. All Right Reserved. | www.cppinstitute.org | Last updated: March 16, 2016

int main(void) { C c1 = {1.Question 2 What is the output of the following program? #include <iostream> using namespace std. cout << c1. 3. | www. struct B { int b. All Right Reserved. 8}. 6.a + c2.a.cppinstitute. }. return 0. 6 B. struct C { A a. }. 7. 2.org | Last updated: March 16.b. c2 = {5. 10 D. B b. 8 C. 2016. float b. } A. float a. struct A { int a. 2016 . }.b << endl. 4}. 12 C++ Institute.

4. } A. 1 }. | www.1. int *p1 = t + 2.org | Last updated: March 16. -1 C.cppinstitute. All Right Reserved. return 0.Question 3 What is the output of the following program? #include <iostream> using namespace std. 2 C++ Institute. *p2 = p1 . int main(void) { int t[4] = { 8. 2016 . cout << *p1 . 2. 2016. 1 D. p1++.p2] << endl.t[p1 . -2 B.

org | Last updated: March 16. } int fun2(int &p) { ++p. c = fun2(b). c.cppinstitute. } int main(void) { int a = 1. int fun1(int p) { ++p. } A. 2016. 8 D. 4 B. 2016 . | www. return 0. 10 C++ Institute. b. return p++. return p++.Question 4 What is the output of the following program? #include <iostream> using namespace std. All Right Reserved. b = fun1(a). 6 C. cout << a + b + c << endl.

1 B. int q) { p[q] *= 2. } void fun(int *p. return 0. fun(v. fun(v. } int main(void) { int *v = fun().0). } void fun(int *p. } int fun(int *p) { delete [] p.org | Last updated: March 16. 2016.0. int q. fun(v. return 0. 2016 . | www. } A. cout << v[1] + v[0] << endl.2).Question 5 What is the output of the following program? #include <iostream> using namespace std. 3 D.1). All Right Reserved. 4 C++ Institute. int *fun(void) { return new int[2].cppinstitute. int r) { p[q] = r. 2 C.1. fun(v).

2016. | www. return c. cout << f2(x) << endl. } A. char f1(char c) { return c == 'z' ? 'a' : c + 1. yza C++ Institute. return 0. xyz C. All Right Reserved. } int main(void) { char x = 'x'.org | Last updated: March 16. cout << f2(x).Question 6 What is the output of the following program? #include <iostream> using namespace std. XYZ B. cout << f2(x). 2016 .cppinstitute. YZA D. } char f2(char &c) { c = f1(c).

3 D. 1 B.org | Last updated: March 16. All Right Reserved. delete [] t[0]. delete [] t[1]. } A. i < 4. 2 C. int main(void) { int *t[2] = { new int[2]. 2016 . 2016. cout << t[0][1] + t[1][0] << endl.Question 7 What is the output of the following program? #include <iostream> using namespace std. new int[2] }. | www. for(int i = 0. 4 C++ Institute.cppinstitute. return 0. i++) t[i % 2][i / 2] = i.

int i = s.org | Last updated: March 16. s = s + t.Question 8 What is the output of the following program? #include <iostream> #include <string> using namespace std. } A. 2 D. | www. return 0. All Right Reserved. t = t + s. 0 B. 3 C++ Institute. int main(void) { string s = "Abc". 2016 .length() < t. int j = s.length(). t = "A".compare(t) > 0. 2016. cout << i + j << endl.cppinstitute. 1 C.

namespace alpha { int var = 1. } namespace beta { int var = alpha::var + 1. 1 B. cout << var << endl. } int main(void) { beta::var += alpha::var. 2016 . { using namespace beta.Question 9 What is the output of the following program? #include <iostream> using namespace std. 4 C++ Institute.org | Last updated: March 16.cppinstitute. } A. All Right Reserved. 2 C. 3 D. | www. 2016. } return 0.

The program will cause a compilation error B. 2 D. All Right Reserved. return 0.b() << endl. class A { int a. } A. public: A(void) { a = 1.org | Last updated: March 16. cout << a.b(). | www. 2016. 3 C++ Institute.Question 10 What is the output of the following program? #include <iostream> using namespace std. } int b(void) { return ++a. 1 C. int main(void) { A a.cppinstitute. 2016 . } }. a.

b = 1.b << endl.a. a. | www.b().a=a.b. 2016. a. return x. All Right Reserved. 10 C. int main(void) { A a. 11 C++ Institute. 01 D. }.a.a. } A.a. int b(void).cppinstitute. } a. 2016 .a = a. return 0.org | Last updated: March 16. The program will cause a compilation error B.b() << a. cout << a.a = 0. }.a.Question 11 What is the output of the following program? #include <iostream> using namespace std.b. } struct { int a. int A::b(void) { int x=a. class A { public: A() { a.b=x.

int main(void) { B *b = new B(). A() { a = 0. } }. The program will cause a compilation error B. 5 C++ Institute. 3 D.org | Last updated: March 16.a << endl. All Right Reserved. } A. 2016. B() : a(0) { } }. class A { public: int a. 1 C.cppinstitute. return 0.Question 12 What is the output of the following program? #include <iostream> using namespace std. } A(int b) { a = b + 1. cout << b->a. | www. 2016 . class B { public: A a.

2 D. 1 C.d(). b. } }. b.x << endl. cout << b. void d() { A::d(). 2016 . | www. 4 C++ Institute. } }.org | Last updated: March 16. 2016. class A { public: int x. int main(void) { B b.cppinstitute. The program will cause a compilation error B. void d() { x /= 2.y = 4. } A.y / b. All Right Reserved.x = b. class B : public A { public: int y.Question 13 What is the output of the following program? #include <iostream> using namespace std. return 0.

class B : public A { public: int relax(void) { return 2. class A { public: int work(void) { return 4. 1 C.org | Last updated: March 16. All Right Reserved. 4 C++ Institute. class C : public A { public: int relax(void) { return 1. int main(void) { A *a0 = new A. 2016. } }. The program will cause a compilation error B.Question 14 What is the output of the following program? #include <iostream> using namespace std.cppinstitute. } }. return 0. *a1 = new B. | www. } }. *a2 = new C. } A. cout << a0 -> work() + static_cast<C*>(a2) -> relax() / static_cast<B*>(a1) -> relax() << endl. 2 D. 2016 .

public: B() : b(2) {} void f(A &a) { a. public: A() : a(4) {} void f(B &b. | www.a /= b. B b.f(*this). } int main(void) { A a. 2 D. } }. } A. 2016 .A &a). int out(void) { return a. } }. int a.Question 15 What is the output of the following program? #include <iostream> using namespace std. a. The program will cause a compilation error (or warning in some compilers) B. All Right Reserved. class A { friend class B.A &a){ b.org | Last updated: March 16. class B { friend class A. 4 C++ Institute.a).f(b. 2016. class B. 1 C.out() << endl. int b.cppinstitute. cout << a. void A::f(B &b. return 0.

int A::a = 1. return 0. class A { public: static int a. 2016 . The program will cause a compilation error B. } }. } catch (string &s) { } cout << A::a << endl. void f(void) { A a.cppinstitute. All Right Reserved. throw string("?").Question 16 What is the output of the following program? #include <iostream> using namespace std. | www. 4 D. A() { a++. try { f(). 2016. } A.org | Last updated: March 16. 5 C++ Institute. 3 C. } int main(void) { A a.

5 C++ Institute. All Right Reserved.org | Last updated: March 16..cppinstitute. 4 D. } catch (runtime_error &e) { a--.. void f(void) { throw domain_error("err"). 2016 . } A. } catch (. try { f(). The program will cause a compilation error B. 3 C.) { a++. | www. return 0. 2016. } int main(void) { int a = 4. } cout << a << endl.Question 17 What is the output of the following program? #include <iostream> #include <exception> #include <stdexcept> using namespace std.

5 C++ Institute. i++. void f(void) { throw 1. } } int main(void) { try { g().cppinstitute.org | Last updated: March 16. } void g(void) { i++. } A.Question 18 What is the output of the following program? #include <iostream> #include <exception> using namespace std. i++. 2016.. 3 C. The program will cause a compilation error B.. return 0. | www. 4 D. 2016 . } cout << i << endl. } catch(int &i) { throw ++i. All Right Reserved.) { i++. int i = 1. } catch(. try { f().

Question 19 What is the output of the following program? #include <iostream> #include <exception> #include <stdexcept> using namespace std. 5 C++ Institute. } catch(. } void g(void) { try { f(). } catch(logic_error &l) { i++. void f(void) { i++. } A. 2016 . 2016. The program will cause a compilation error (or warning in some compilers) B. } cout << i << endl.. 4 D.cppinstitute. } } int main(void) { try { g(). | www. All Right Reserved.) { i++.. class A : public runtime_error { public: A() : runtime_error("?") {} }. i++. throw B(). i++. int i = 3. 3 C. class B : public logic_error { public: B() : logic_error("!") {} }. return 0.org | Last updated: March 16. } catch(A &a) { throw A().

int main(void) { A i = 2. class A { public: int v. All Right Reserved. 4 C++ Institute. 2016 .cppinstitute. i && 2.org | Last updated: March 16.Question 20 What is the output of the following program? #include <iostream> using namespace std. } A. 2016. 2 D. 1 C. return 0. cout << i << endl. A():v(1) {} A(int i):v(i) {} void operator&&(int a) { v = -v. The program will cause a compilation error B. } }. | www.

return 0. 2016. All Right Reserved. 2016 . 4 C++ Institute. } A. } }. int main(void) { A i = 2. cout << i. | www. A():v(1) {} A(int i):v(i) {} void operator**(int a) { v *= a. 2 D.v << endl.Question 21 What is the output of the following program? #include <iostream> using namespace std. 1 C.org | Last updated: March 16. i ** 2. class A { public: int v.cppinstitute. The program will cause a compilation error B.

return 0. 4 C++ Institute. } A. 1 C. 2016 . | www. enum e { a=1. return x.Question 22 What is the output of the following program? #include <iostream> using namespace std. 2016. All Right Reserved. cout << int(f--) << endl.b. 3 D. The program will cause a compilation error (or warning in some compilers) B.d }. } int main(void) { e f = c.cppinstitute.org | Last updated: March 16.c. e& operator--(e &x) { x = b.

org/cpa-c-certified-associate-programmer-certification Exam registration: http://pearsonvue.ANSWER KEY 1 2 3 4 5 6 7 8 9 10 D C B C D D C C C D 11 12 13 14 15 16 17 18 19 20 B B C D C B D B D A 21 22 A A More information about the CPA exam is available at: http://cppinstitute.org | Last updated: March 16. 2016.cppinstitute. 2016 .com/cpp C++ Institute. All Right Reserved. | www.