User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 455,974 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,766 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 3053 | Replies: 2
Reply
Join Date: Jul 2004
Posts: 31
Reputation: Sukhbir is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Sukhbir Sukhbir is offline Offline
Light Poster

unsigned/signed problem

  #1  
Aug 26th, 2004
consider the programme
void main()
{
unsigned i=1;
signed j=-1;
if(i<j)
printf("less");
}

output is:
less
why can someone explain me
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2004
Location: India
Posts: 15
Reputation: shalin is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
shalin's Avatar
shalin shalin is offline Offline
Newbie Poster

Re: unsigned/signed problem

  #2  
Aug 26th, 2004
hi sukbhir
which compiler u r using?
some times it depends on the compiler.
in c lang. conditional operators compares signed values.

try this...

#include<stdio.h>

main()
{
unsigned int i=1;
signed int j =-1;
if((signed)i<j)
printf("less");
else
printf("greater");
}
Reply With Quote  
Join Date: Apr 2004
Posts: 3,755
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: unsigned/signed problem

  #3  
Aug 26th, 2004
>why can someone explain me

You are comparing signed and unsigned values. The signed value gets promoted to an unsigned value for the comparison and ends up being very large.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 2 (0 members and 2 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 9:18 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC