[LCP]sign problem

Arindam Chatterjee arindamc at alumnux.com
Thu Aug 9 18:28:04 UTC 2001


actually the same value gets stored when you are storing negative number
in a signed or unsigned
variable.  do
  unsigned int x = -9;
  int y = -9;
  printf("x = %x   y = %x ", x, y);

How are u printing ? If u use printf("%d", ...) to print the unsigned
number then it will show u the negative
number, bcoz printf is changing it to signed value. You have to print
using printf("%u") to get what u
want.

HTH,
arindam C.

Srinath Thiruvengadam wrote:

>  hello all,
>
> in one of my programs , i used an unsigned int variable.i had a
> problem in this program. i traced the execution and  found that in one
> placea negative value goes into the variable. howz that possible?
> shouldnt the program endabnormally on receiving a signed number??? and
> when i print the number the no. prints as anegative number. i thought
> the signed would notbe used for unsigned variables. whatz happening
> inside??? ThanksSrinath.




More information about the linuxCprogramming mailing list