BlackFriday 2024! 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 9 Question 97 Discussion

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

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

#include

#include

#include

using namespace std;

int main ()

{

int t[] = {1, 2 ,3 ,4 ,5, 6 , 7, 8 , 9, 10};

vectorv1(t, t+10);

dequed1(t, t+10);

d1.empty();

v1.empty();

if (v1.isempty())

{

cout<<"I am empty ";

}

else

{

cout<<"I am not empty ";

}

cout<

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Gregoria
27 days ago
Wait, wait, wait... so you're telling me that 'empty' doesn't actually make things... well, empty? Looks like the joke's on us, folks!
upvoted 0 times
Rashad
2 days ago
User 3: So the program will output 'I am not empty 10 10'.
upvoted 0 times
...
Jin
4 days ago
User 2: I guess it's more about checking if it's empty rather than making it empty.
upvoted 0 times
...
Gary
11 days ago
Yeah, 'empty' doesn't actually make things empty.
upvoted 0 times
...
...
Lavelle
1 months ago
This question is a real head-scratcher! I'm going with D though, because I'm pretty sure the empty() function doesn't change the size of the containers.
upvoted 0 times
Whitney
13 days ago
I am not empty 10 10
upvoted 0 times
...
Gail
14 days ago
I am not empty
upvoted 0 times
...
...
William
1 months ago
I'm not sure, but I think the correct answer is D) program outputs: I am not empty 10 10 because the vector and deque are filled with 10 elements.
upvoted 0 times
...
Maryanne
1 months ago
I agree with Erinn, the vector and deque are initialized with values so they are not empty.
upvoted 0 times
...
Princess
1 months ago
I'm a bit rusty on my C++ containers, but I think D has to be the right answer. The empty() function doesn't affect the size, it just checks if the container is empty or not.
upvoted 0 times
...
Lenna
1 months ago
Haha, looks like someone's trying to trick us with a classic 'empty' vs 'size' confusion. D is the winner here!
upvoted 0 times
Paris
22 days ago
10 10
upvoted 0 times
...
Bobbye
23 days ago
I am not empty
upvoted 0 times
...
Clay
26 days ago
I am not empty
upvoted 0 times
...
...
Erinn
1 months ago
I think the answer is B) program outputs: I am not empty 0 0
upvoted 0 times
...
Mira
2 months ago
The correct answer is D. The program outputs 'I am not empty 10 10' because the vector and deque are both initialized with the array 't' and the empty() function does not change the size of the containers.
upvoted 0 times
Leota
1 months ago
That makes sense, the containers are initialized with the array 't'.
upvoted 0 times
...
Leota
2 months ago
I am not empty 10 10
upvoted 0 times
...
...

Save Cancel