main()
{
float me =1.1;
double you=1.1;
if(me==you)
printf(“i love embedded c”);
else
printf(“i love embeddedgoogle”);
}
Ans
I love emeddedgoogle
Explanation:
For floating poit members (float, double, long double) the values cannot predicted exactly, Depending on the number of bytes, the precession with of the represented varies,. Float takes bytes and long double takes 10 bytes, so float stores 0.9 with less than long double.
Rule of thumb;
Never compare or at-least be cautious when using floating point numbers with relational operators, (==,>,<,<=,>=,!+)
What is output of this program?
main()
{
int c[]={2,8,3,4,4,6,7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++)
{
printf(“%d”,*c);
++q;
}
for(j=0;j<5;j++)
{
printf(“%d”,*p);
++p;
}
Ans
2 2 2 2 2 2 2 3 4 6 5
Explanation:
Initially pointer c Is assigned to both p and q. in the first loop, since only q is incremented and not c, the value 2 will ne printed 5 times, in second loop p itself is incremented . so the values 2 3 4 6 5 will be printed.
No comments:
Post a Comment