Free CPP Exam Braindumps
C++ Certified Professional Programmer Questions 71–75 (page: 16)

Updated On: 9-Feb-2026

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

#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; } void setA(int a) { this?>a = a; }
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
deque<int> d (t,t+15);
int number = count(d.begin(), d.end(), 2);
cout<< number<<endl;
return 0;
}

Program outputs:

  1. 4
  2. 3
  3. 2
  4. 0
  5. compilation error

Answer(s): A



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

#include <vector>
#include <iostream>
int main ()
{
std::vector<int> v1;
for(int i = 10; i>0; i??)
{
v1.push_back(i);
}
std::vector<int>::iterator it = v1.begin();
int sum = 0;
while(it != v1.end())
{
sum+=it++;
}
std::cout<<*v1.erase(v1.begin(),v1.end()?3)<<" "<<sum <<std::endl;

return 0;
}

  1. program outputs 3 55
  2. compilation error
  3. program outputs 3 45
  4. program outputs 7 55

Answer(s): B



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

include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
using namespace std;

int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector<int> v1(t, t + 10);
deque<int> d1(t, t + 10);
set<int> s1(t, t + 10);
cout<<find(v1.begin(), v1.end(), 6)<<" "<<find(d1.begin(), d1.end(), 6)<<" "<<find(s1.begin(), s1.end(), 6);
return 0;
}

  1. program outputs: 6 6 6
  2. program outputs: 3 3 5
  3. program outputs: 3 6 5
  4. compilation error
  5. none of these

Answer(s): D



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

#include <iostream>

using namespace std;

template <typename T>
class A {
T _v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T a) { _v+=a; }
template <class U>
U get(U a) {
return (U)(_v);
}
};

int main()
{
A<int> a(1);
a.add(10);
cout.setf( ios::showpoint);
cout << a.getV() << " " << a.get(1.0)<<endl;
return 0;
}

  1. program will display: 11 11
  2. program will not compile
  3. program will display: 11.0000 11
  4. program will display: 11 11.000

Answer(s): D



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

#include <iostream>

using namespace std;

void g(int a)
{
cout<<a?1<<endl;
}

template<class A>
void g(A a)
{
cout<<a+1<<endl;
}


int main()
{
int a = 1;
g(a);
return 0;
}

  1. program displays: 0
  2. program displays: 2
  3. compilation error
  4. runtime exception

Answer(s): A



Viewing page 16 of 47
Viewing questions 76 - 80 out of 228 questions


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

AI Tutor AI Tutor 👋 I’m here to help!