consider the programme

void main()
{
unsigned i=1;
signed j=-1;
if(i<j)
printf("less");
}

output is:
less
why can someone explain me

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");
}

>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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.