Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPP Topic 5 Question 106 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 106
Topic #: 5
[All CPP Questions]

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

#include

#include

#include

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 d (t,t+15);

int number = count(d.begin(), d.end(), 2);

cout<< number<

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Asha
2 months ago
This is too easy, the answer has to be B. I mean, come on, counting occurrences of a number? That's like programming 101. Unless... there's some kind of sneaky twist I'm missing. Nah, I'm sticking with B.
upvoted 0 times
Ilene
24 days ago
I'm with you guys, B seems like the correct answer here.
upvoted 0 times
...
Cecilia
28 days ago
Yeah, counting occurrences is a basic concept. B sounds right to me too.
upvoted 0 times
...
Arlette
1 months ago
I agree, it seems pretty straightforward. B is the most likely answer.
upvoted 0 times
...
...
Stevie
2 months ago
Haha, the code looks like it was written by a prankster. Throwing in a random class A just to confuse us. But I'm not falling for that trap, I'm going with B!
upvoted 0 times
...
Adelle
2 months ago
Wait, wait, wait... why is there a class A in the code? Is that just a red herring or is it somehow relevant? Ah, who cares, I'll just go with the most straightforward answer, which is B.
upvoted 0 times
Odette
1 days ago
No, the class A doesn't affect the output, the answer is B for sure.
upvoted 0 times
...
Tamera
5 days ago
I'm not sure about that, I think the class A might have some impact on the output.
upvoted 0 times
...
Andrew
8 days ago
Yeah, I agree, the code is just counting the number 2 in the deque, so the answer is B.
upvoted 0 times
...
Salley
16 days ago
I think the class A is just there to confuse us, the answer is B.
upvoted 0 times
...
...
Wava
2 months ago
Oh, that makes sense. I see your point now.
upvoted 0 times
...
Ira
2 months ago
I disagree, I believe the answer is A) 4 because there are 4 occurrences of the number 2 in the deque
upvoted 0 times
...
Cornell
2 months ago
Hmm, this looks like a simple problem of counting occurrences of a number in a container. I'll go with option B, since 2 appears 3 times in the given array.
upvoted 0 times
Fatima
20 days ago
So, the output will be 3.
upvoted 0 times
...
Brande
1 months ago
Yes, because there are 3 occurrences of 2 in the array.
upvoted 0 times
...
Delbert
1 months ago
I agree, it should be 3.
upvoted 0 times
...
Rueben
2 months ago
I think the answer is B.
upvoted 0 times
...
...
Wava
2 months ago
I think the answer is B) 3
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77