Cyber Monday 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
2 months 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
1 months ago
User 3: So the program will output 'I am not empty 10 10'.
upvoted 0 times
...
Jin
1 months ago
User 2: I guess it's more about checking if it's empty rather than making it empty.
upvoted 0 times
...
Gary
1 months ago
Yeah, 'empty' doesn't actually make things empty.
upvoted 0 times
...
...
Lavelle
2 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
1 months ago
I am not empty 10 10
upvoted 0 times
...
Gail
1 months ago
I am not empty
upvoted 0 times
...
...
William
2 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
2 months ago
I agree with Erinn, the vector and deque are initialized with values so they are not empty.
upvoted 0 times
...
Princess
2 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
2 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
2 months ago
10 10
upvoted 0 times
...
Bobbye
2 months ago
I am not empty
upvoted 0 times
...
Clay
2 months ago
I am not empty
upvoted 0 times
...
...
Erinn
2 months ago
I think the answer is B) program outputs: I am not empty 0 0
upvoted 0 times
...
Mira
3 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
2 months ago
That makes sense, the containers are initialized with the array 't'.
upvoted 0 times
...
Leota
3 months ago
I am not empty 10 10
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