exam questions

Exam CPP All Questions

View all questions & answers for the CPP exam

Exam CPP topic 2 question 124 discussion

Actual exam question from C++ Institute's CPP
Question #: 124
Topic #: 2
[All CPP Questions]

What happens when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
using namespace std;
class A
{
int a,b;
public:
A & operator =(const A & c) { a = c.a; return *this;}
A():a(0),b(0){}
void setA(int a) {this?>a = a;} void setB(int b) {this?>b = b;} int getA() {return a;} int getB() {return b;}
};

int main ()
{
vector<A>v;
A a;
a.setA(10); a.setB(11);
v.push_back(a);
A b = v.front(); v.pop_back();
cout<<b.getB()<<" "<<b.getA()<<endl;
return 0;
}

  • A. program outputs 11 10
  • B. compilation error
  • C. program outputs 0 10
  • D. program outputs 10 0
  • E. program outputs 11 0
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Currently there are no comments in this discussion, be the first to comment!
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...