Pre and Post Increment in System Verilog

Status
Not open for further replies.

sunidrak

Full Member level 1
Joined
Apr 12, 2012
Messages
97
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Bengaluru, India
Visit site
Activity points
1,738
hi

Can any body please explain
Pre and post Incrment in system verilog and reason for this output



module increment;
integer i=3,z;
initial
begin
z=i++/i;
$display("i=%d,z=%d "i,z);
end
endmodule

Output
# i=4
# z=0


Regards
SUNIL
 

The numerator of your expression i++/i is definitely 3, but the denominator could be 3 or 4. And 3/4 as an integer is 0.

The LRM explains this quite well. See section 11.4.2 Increment and decrement operators.

Don't have a copy of the LRM?, get a free copy.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…