FIND THE OUTPUT IF THE INPUT IS 5 5.75
void main()
{
int i=1;
float f=2.25;
scanf("%d%f",&i,&f);
printf("%d %f",,i,f);
}
ANSWER IS 5 AND 2.25 WHY?

Answer Posted / suman halder

There is a tiny mistake in the question..It should be..

FIND THE OUTPUT IF THE INPUT IS 5 5.75

void main()
{
int i=1;
float f=2.25;
scanf("%d %d",&i,&f);
printf("%d %f",,i,f);
}
ANSWER IS 5 AND 2.25 WHY?

The answer of this question actually lies within the question itself..
if we look at the scanf statement ,then the actual reason of the output will be revealed..
In scanf,we are trying to get the input into a floating point number through %d format specifier which is the format specifier for integers..here,lies the anomaly..
nothing actually get stored within f through scanf ,so the previous value of f is retained..and that gets printed..
thats it..

*** if we try the reverse of it.i.e using %f,we wanna get the value into an integer..the compiler may report some error like "floating point format not linked"...we can abstain the error by intoducing a linkfloat function but still there will be some anomaly in the value that get stored in the variable ..so,to get the expected output we need to specify the correct format specifier....dnt trust printf or scanf to perform the proper typecasting for u..
do it explicitly..

linkfloat()
{
float a,*b;
b=&a;
a=*b;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

please explain every phase in the "SDLC" in the dotnet.

2173


Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon

1730


What is the meaning of ?

601


in linking some of os executables are linking name some of them

1645


What are the uses of null pointers?

585






What is the difference between union and structure in c?

564


What is the function of volatile in c language?

658


What is #line in c?

554


Explain the bubble sort algorithm.

632


What is a structure and why it is used?

611


any C program contains only one function, it must be a) void () b) main () c) message () d) abc ()

689


which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above

1405


What does %c mean in c?

639


write a programming in c to find the sum of all elements in an array through function.

1698


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

594