Difficulty: Medium · Puzzle 3 of 6 · Topic: Queue and Array Puzzles
What values are returned by `pop_front` and `pop_back` on an empty queue?
module p3;
int q[$];
int a, b;
initial begin
a = q.pop_front();
b = q.pop_back();
$display("a=%0d b=%0d size=%0d", a, b, q.size());
end
endmoduleSV returns default value of element type when popping from an empty queue.
1) Queue starts empty.
2) `pop_front()` returns default `int` value 0 when queue is empty.
3) `pop_back()` on still-empty queue also returns 0.
4) Queue size remains 0.Answer: a=0, b=0, size=0
Some interviewees expect runtime fatal behavior and skip default-value semantics.
How would behavior differ for `string q[$]` when popping empty?