Uday Oberio wrote:
> hello everyone
> i m very new in this so please help.
> thanx in advace,,,,
>
> my problem is this : -
>
> #include<stdio.h>
> #include<conio.h>
> void main()
> {
> int a=-5;
> unsigned int r=2000;
> if(a>r)
> printf( " a is greater than r ");
> else
> printf(" r is greater than a");
> }
>
>
> In this programe the output is = a is greater than r why please explain
> me how it can be....
> and also tel me i m very new in this filed please tell me from where should
> i get the knowldge of 'C' programming...
> thanx a lot in advance...
> arun.,,,,,
> waiting for u r reply....
Turn up your compiler warnings high enough such that you receive a
warning of "unsigned/signed comparison" on the line with 'if (a > r)'.
To fix the problem. you need to cast r to int:
if (a > (int)r)
To get the expected output.
Also, upgrade your compiler to something more recent. conio.h indicates
you are using Turbo C/C++...an ancient compiler.
It is 'int main()' NOT 'void main()' and you are supposed to return an
int (usually zero) from main().
To everyone else who is making grandiose statements about the
sizeof(int) being a specific bit length: The Standard, IIRC, only makes
_minimal_ bit length demands on each data type. The compiler is free to
make an int 4099 bits in length if it so desires. Get at least a Draft
copy as recommended when you joined the group (in the group Welcome
message) and read it.
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/