C++ Institute CPA Exam
C++ Certified Associate Programmer (Page 7 )

Updated On: 26-Jan-2026

What is the output of the program?

#include <iostream>
#include <string>

using namespace std;

int main()
{
string s1[]= {"H" , "t" };
string s;

for (int i=0; i<2; i++) {
s = s1[i];
if (i==0)
s.insert(1,"ow");
else
s.push_back('o');
cout << s;
}
return( 0 );
}

  1. It prints: Hoto
  2. It prints: Ht
  3. It prints: toHo
  4. It prints: Howto

Answer(s): D



What is the output of the program given below?

#include <iostream>

using namespace std;

int main (int argc, const char * argv[])
{
float f=?10.501;
cout<<(int)f;
}

  1. 0
  2. 11
  3. ?10
  4. ?11

Answer(s): C



What is the output of the program?

#include <iostream>
#include <string>

using namespace std;

class First
{
string name;
public:
First() {
name = "Alan";
}
void setName(string n) {this?>name = n;}
void setName() {this?>name = "John";}
void Print(){
cout << name;
}
};

int main()
{
First ob1,*ob2;
ob2 = new First();
First *t;
t = &ob1;
t?>setName();
t?>Print();
t = ob2;
t?>setName("Steve");
ob2?>Print();
}

  1. It prints: JohnSteve
  2. It prints: AlanAlan
  3. It prints: AlanSteve
  4. It prints: JohnAlan

Answer(s): A



What happens when you attempt to compile and run the following code?

#include <iostream>
#include <string>

using namespace std;


class complex{
double re, im;
public:
complex() : re(1),im(0.3) {}
complex(double n) { re=n,im=n;};
complex(int m,int n) { re=m,im=n;}
complex operator+(complex &t);
void Print() { cout << re << " " << im; }

};

complex complex::operator+ (complex &t){
complex temp;
temp.re = this?>re + t.re;
temp.im = this?>im + t.im;
return temp;
}


int main(){
complex c1(1),c2(2),c3;
c3 = c1 + c2;
c3.Print();
}

  1. It prints: 1 1.5
  2. It prints: 2 1.5
  3. It prints: 3 3
  4. It prints: 0 0

Answer(s): C



What happens when you attempt to compile and run the following code?

#include <iostream>

using namespace std;


int main()
{
int i = 0;
do {
i++;
if (i==3)
break;
cout<<i;
}
while(i < 5);
return 0;
}

  1. It prints: 12
  2. It prints: 1
  3. It prints: 0
  4. No output

Answer(s): A



Viewing page 7 of 45
Viewing questions 31 - 35 out of 220 questions



Post your Comments and Discuss C++ Institute CPA exam prep with other Community members:

Join the CPA Discussion