I have been preparing for interview when I bumped up with this question.
#include<stdio.h>
int main()
{
unsigned long a = 100;
long b = -1;
if(b>a)
printf("YES");
else
printf("No");
}
The output of the program is to be found. The answer is YES
can anyone please explain me how this is the correct answer? I analyzed and found that the answer is YES when atleast one of a and b has unsigned qualifier. When both are just long then it prints NO
EDIT:
There is one other question which made me think much. Here is the code
#include<stdio.h>
int main()
{
float t = 1.0/3.0;
if(t*3 == 1.0)
printf("yes");
else
printf("no");
}
The answer for the code is no
but I am not able to decipher how it is obtained. Also, when I assume a variable a = t*3
and compare it in the if statement, I get the output as yes
I am trying to learn the concepts. So Kindly help me by explaining how these 2 programs produce the respective output.
Thanks