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
Explain the use of 'auto' keyword in c programming?
Why main is not a keyword in c?
WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER
What is exit() function?
How many parameters should a function have?
Is array name a pointer?
Do you have any idea how to compare array with pointer in c?
What the advantages of using Unions?
Is c weakly typed?
write a sorting prgm to sort 50 nos and sum them and also remove all the occurrences of 15 and print it?
Explain is it better to bitshift a value than to multiply by 2?
A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM
Do character constants represent numerical values?
What is a structure member in c?
Why do some versions of toupper act strangely if given an upper-case letter?