Questions for the CPA were updated on : Nov 21 ,2025
What will variable "y" be in class B?
class A {
int x;
protected:
int y;
public:
int age;
};
class B : public A {
string name;
public:
void Print() {
cout << name << age;
}
};
C
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1[]= {"How" , "to" };
s1[0].swap(s1[1]);
for (int i=0; i<2; i++) {
cout << s1[i];
}
return( 0 );
}
B
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
const char *s;
char str[] = "Hello";
s = str;
while(*s) {
cout << *s++;
}
return 0;
}
B
What will be the output of the program?
#include <iostream>
#include <string>
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;
}
C
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
#define A 1
int main()
{
#if A
cout<<"Hello";
#endif
cout<<"world";
return 0;
}
A
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int i = 4;
while(i >= 0) {
cout<<i;
i??;
}
return 0;
}
A
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
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";
}
}
A
What happens when you attempt to compile and run the following code?
#include <iostream>
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;
}
B
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
void setAge(int a=20) {age = a;}
void Print() { cout << age;}
};
int Base::age=0;
int main () {
Base a;
a.setAge(10);
a.Print();
a.setAge();
a.Print();
return 0;
}
C
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void fun(char*);
int main()
{
char t[4]={'0', '1', '2', '3'};
fun(&t[0]);
return 0;
}
void fun(char *a)
{
cout << *a;
}
C
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
A() { cout << "A no parameters";}
A(string s) { cout << "A string parameter";}
A(A &a) { cout << "A object A parameter";}
};
class B : public A {
public:
B() { cout << "B no parameters";}
B(string s) { cout << "B string parameter";}
};
int main () {
A a1;
A a2("Test");
B b1("Alan");
return 0;
}
A
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 tab[5]={1,2,3};
for (int i=0; i<5; i++)
cout <<tab[i];
return 0;
}
B
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class A {
public:
void Print(){ cout<<"A";}
};
class C:public A {
public:
virtual void Print()=0;
};
int main()
{
C obj3;
obj3?>Print();
}
D
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
enum state { ok, error, warning};
enum state s1, s2, s3;
s1 = ok;
s2 = warning;
s3 = error;
s4 = ok;
cout << s1<< s2<< s3;
return 0;
}
B
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};
D.
char c;
A, C