Re: comparison between signed and unsigned int
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Fri, 21 Sep 2007 10:54:32 -0700
compcreator@xxxxxxxxx writes:
I have tried the following program. The problem is it is printing
False
I checked values for a and b but there is something wrong with the
comparison.
I thing it might be because of signed and unsigned conversion.
Either b is upgraded to unsigned and the resulting value during
comparison is > 5 or a is downgraded to signed and the resulting value
is lower than -1.
void main()
{
unsigned int a = 5;
signed int b = -1;
if(b <= a)
printf("True");
else
printf("False");
}
Can somebody explain why is this happening....?
In addition to reading the FAQ, you need to change 'void main()' to
'int main(void)', add '#include <stdio.h>', add a terminating newline
to each of your output strings (or use puts()), and add a 'return 0;'
at the end of your program.
You should also find out how to persuade your compiler to give you
more warnings; it could have told you about most of these problems.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- References:
- comparison between signed and unsigned int
- From: compcreator
- comparison between signed and unsigned int
- Prev by Date: Re: sizeof and VLAs (was Re: Another sizeof question)
- Next by Date: Re: [OT] Re: sob..Someone can help me????plsss
- Previous by thread: Re: comparison between signed and unsigned int
- Next by thread: Re: comparison between signed and unsigned int
- Index(es):
Relevant Pages
|