I was trying to do the exercises in the chris spear’s book
``` verilog
module queue_prblm8;
int queue[3]='{2,-1,127};
initial begin
$display("Sum of the queue is %0d",queue.sum());
queue.sort;
$display("Min value in the queue is %0d",queue[0]);
$display("Max value in the queue is %0d",queue[3]);
$display("Queue after sorting is %p",queue);
$display("Index of the negative value %d",queue.find_first_index(x) with (x < 0));
$display("Positive values in the queue is %p",(queue.find() with (item > 0)));
queue.reverse;
$display("queue after reversing %p",queue);
end
endmodule
This is the code and i am using synopsys simulator
> Sum of the queue is 128
...
Index of the negative value 166757000
and this is the output i am getting
doesn’t return an index. It returns a queue that will either contain the desired index or be empty if no such index exists. What you’re printing is the “memory location” of the array. Change your format specifier to
%p
Also note that you’re printing queue[3] after doing max(), but the array only has 3 elements.