Unexpected output

I wrote a code for a question but a line isn’t giving expected output. To make it simple, I have removed other lines.
https://ide.codingblocks.com/s/44458

Can you help me to understand why last line isn’t giving (-1).

Really nice question, took me long to figure this out. Size function returns “unsigned integer”, which cannot store a negative number or -1 in your case. -1 is an signed integer with negative sign.
Solution:
Save the size in normal int type variable and use it normally. int will create a signed variable automatically, that we usually want.

1 Like