CPA-21-02 C++ Institute CPA - C++ Certified Associate Programmer Free Practice Exam Questions (2025 Updated)
Prepare effectively for your C++ Institute CPA-21-02 CPA - C++ Certified Associate Programmer certification with our extensive collection of free, high-quality practice questions. Each question is designed to mirror the actual exam format and objectives, complete with comprehensive answers and detailed explanations. Our materials are regularly updated for 2025, ensuring you have the most current resources to build confidence and succeed on your first attempt.
What will happen when you attempt to compile and run the following code?
#include
using namespace std;
#define A 1
int main()
{
#if A
cout<<"Hello";
#endif
cout<<"world";
return 0;
}
What happens when you attempt to compile and run the following code?
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; i<2;i++)
(bc++)->print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include
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();
}
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;
c1.print();
return 0;
}
Which of the following operators accept integer arguments only? (Choose two.)
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int fun(int x) {
return 2*x;
}
int main(){
int i;
i = fun(0.5) || fun(0);
cout << i;
return 0;
}
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< }
Which of the following is a correct way to define the function fun() in the program below?
#include
#include
#include
using namespace std;
int main()
{
int a[2][2];
fun(a);
return 0;
}
The following declaration:
int i = 0b10;
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
int i = 5;
do {
i??;
cout<
}
while(i >= 0);
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main() {
int i, j;
for(i = 0; i < 2; i++) {
for(j = i; j < i + 1; j++)
if(j == i)
continue;
else
break;
}
cout << j;
return 0;
}
Which code line inserted instead of the comment below will cause the program to produce the expected output?
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
int i = 4;
while(i >= 0) {
cout<
i??;
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
void fun(int*);
int main()
{
int *x;
int i=2;
x=&i;
fun(x);
cout<
return 0;
}
void fun(int *i)
{
*i = *i * *i;
}
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 A {
public:
virtual void Print(){ cout<< "B";}
};
class C:public B {
public:
void Print(){ cout<< "C";}
};
int main()
{
A ob1;
B ob2;
C ob3;
B *obj;
obj = &ob2;
obj?>Print();
obj = &ob3;
obj?>Print();
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
int i = 0;
do {
i++;
if (i==3)
break;
cout<
}
while(i < 5);
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int op(int x, int y);
float op(int x, float y);
int main()
{
int i=1, j=2, k;
float f=0.3;
k = op(i, j);
cout<< k << "," << op(0, f);
return 0;
}
int op(int x, int y)
{
return x+y;
}
float op(int x, float y)
{
return x?y;
}
What is the output of the program given below?
#include
using namespace std;
int main (int argc, const char * argv[])
{
float f=?10.501;
cout<<(int)f;
}
What is the output of the program given below?
#include
using namespace std;
int main (int argc, const char * argv[])
{
enum state { ok, error, warning};
enum state s1, s2, s3, s4;
s1 = ok;
s2 = warning;
s3 = error;
s4 = ok;
cout << s1<< s2<< s3<< s4;
return 0;
}