what is the output of the following program?
#include<stdio.h>
void main()
{
float x=1.1;
while(x==1.1)
{
printf("\n%f",x);
x=x-0.1;
}
}

Answer Posted / shibumon alampatta

No output; since (x == 1.1) will return false.
Explanantion:
First of all we shall look into the binary representation of
decimal number 1.1. It is 1.00011001100110011..... reccuring
infinite fractional part. And in the expression (x == 1.1),
x is a float and 1.1 is double constant. So their precisions
are different and float x = 1.1 and the double constant 1.1
will not be equal. So if we make double x = 1.1, instaed of
float it will work. Also if it is float x = 1.5 then the
expression (x == 1.5) will return true; because binary form
of 1.5 is 1.1; which is finite and both flaot and double
will have same value.

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can you invoke another program from within a C program?

609


What does it mean when the linker says that _end is undefined?

623


What is the difference between memcpy and memmove?

595


Where does the name "C" come from, anyway?

637


Is c is a low level language?

555






Explain that why C is procedural?

649


Explain about the functions strcat() and strcmp()?

596


How can I manipulate strings of multibyte characters?

631


What does typeof return in c?

633


What is a MAC Address?

622


What is indirection? How many levels of pointers can you have?

650


Explain output of printf("Hello World"-'A'+'B'); ?

967


This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory

719


How is a macro different from a function?

649


What is the use of function overloading in C?

669